Skip to content

Commit

Permalink
fix(routing): Use dynamic router basename (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperkid123 authored and cdcabrera committed Nov 29, 2021
1 parent 8ada964 commit 62fc2e4
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/AppEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '@patternfly/react-styles/css/components/Select/select.css';

const AppEntry = () => (
<Provider store={store}>
<BrowserRouter basename={routerHelpers.baseName}>
<BrowserRouter basename={routerHelpers.dynamicBaseName()}>
<App />
</BrowserRouter>
</Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ exports[`Authentication Component should return a message on 401 error: 401 erro

exports[`Authentication Component should return a redirect on 418 error: 418 error 1`] = `
<Redirect
baseName="/"
isForced={false}
route="/optin"
routes={
Expand Down Expand Up @@ -441,7 +440,6 @@ exports[`Authentication Component should return a redirect on a specific 403 err

exports[`Authentication Component should return a redirect on a specific 403 error and error code: 403 redirect error 1`] = `
<Redirect
baseName="/"
isForced={false}
route="/optin"
routes={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`Redirect Component should handle a forced redirect: forced route 1`] =
exports[`Redirect Component should handle a forced redirect: forced route, replace 1`] = `
Array [
Array [
"/dolor?dolor=sit",
"/subscriptions/dolor?dolor=sit",
],
]
`;
Expand Down
2 changes: 1 addition & 1 deletion src/components/router/__tests__/redirect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Redirect Component', () => {
mockReplace.mockClear();
},
{
url: 'http://lorem/ipsum?dolor=sit'
url: 'http://lorem/subscriptions/ipsum?dolor=sit'
}
);
});
Expand Down
11 changes: 5 additions & 6 deletions src/components/router/redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { helpers } from '../../common';
* A routing redirect.
*
* @param {object} props
* @param {string} props.baseName
* @param {boolean} props.isForced
* @param {string} props.route
* @param {string} props.routes
* @param {string} props.url
* @returns {Node}
*/
const Redirect = ({ baseName, isForced, route, routes, url }) => {
const Redirect = ({ isForced, route, routes, url }) => {
const baseName = routerHelpers.dynamicBaseName();

/**
* Bypass router, force the location.
*/
Expand All @@ -40,11 +41,10 @@ const Redirect = ({ baseName, isForced, route, routes, url }) => {
/**
* Prop types.
*
* @type {{isRedirect: boolean, route: string, routes: Array, isReplace: boolean, baseName: string, url: string,
* @type {{isRedirect: boolean, route: string, routes: Array, isReplace: boolean, url: string,
* isForced: boolean}}
*/
Redirect.propTypes = {
baseName: PropTypes.string,
isForced: PropTypes.bool,
route: PropTypes.string,
routes: PropTypes.array,
Expand All @@ -54,11 +54,10 @@ Redirect.propTypes = {
/**
* Default props.
*
* @type {{isRedirect: boolean, route: string, routes: Array, isReplace: boolean, baseName: string, url: string,
* @type {{isRedirect: boolean, route: string, routes: Array, isReplace: boolean, url: string,
* isForced: boolean}}
*/
Redirect.defaultProps = {
baseName: routerHelpers.baseName,
isForced: false,
route: null,
routes: routerHelpers.routes,
Expand Down
2 changes: 1 addition & 1 deletion src/components/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const Router = ({ routes } = {}) => {
};

const routeDetail = {
baseName: routerHelpers.baseName,
baseName: routerHelpers.dynamicBaseName(),
errorRoute: activateOnErrorRoute,
routes,
routeItem: { ...item },
Expand Down

0 comments on commit 62fc2e4

Please sign in to comment.