Skip to content

Commit

Permalink
Add some comments to the CRA example for hash routing (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath authored Jun 24, 2020
1 parent bc45699 commit 73a2b42
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/cra-react-router/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Error } from './Error';
import { Loading } from './Loading';
import { Users } from './Users';

// Use `createHashHistory` to use hash routing
export const history = createBrowserHistory();

function App() {
Expand Down
8 changes: 7 additions & 1 deletion examples/cra-react-router/src/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ export const ProtectedRoute = ({
component,
...args
}: React.PropsWithChildren<any>) => (
<Route component={withAuthenticationRequired(component)} {...args} />
<Route
component={withAuthenticationRequired(component, {
// If using a Hash Router, you need to pass the hash fragment as `returnTo`
// returnTo: () => window.location.hash.substr(1),
})}
{...args}
/>
);
3 changes: 3 additions & 0 deletions examples/cra-react-router/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import App, { history } from './App';
import { Auth0Provider } from '@auth0/auth0-react';

const onRedirectCallback = (appState: any) => {
// If using a Hash Router, you need to use window.history.replaceState to
// remove the `code` and `state` query parameters from the callback url.
// window.history.replaceState({}, document.title, window.location.pathname);
history.replace((appState && appState.returnTo) || window.location.pathname);
};

Expand Down

0 comments on commit 73a2b42

Please sign in to comment.