Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will vue-router hash mode be supported? #100

Closed
ksakiyama opened this issue Mar 22, 2020 · 2 comments
Closed

Will vue-router hash mode be supported? #100

ksakiyama opened this issue Mar 22, 2020 · 2 comments

Comments

@ksakiyama
Copy link

Hi,

These samples works well only in vue-router history mode. But the default for vue-router is hash mode. Do you have a plan to support hash mode in the future?

@adamjmcgrath
Copy link
Contributor

Hi @ksakiyama ,

You should be able to support hash mode in Vue by changing your onRedirectCallback handler to remove the query params from the redirected page.

eg: In https://github.com/auth0-samples/auth0-vue-samples/blob/master/02-Calling-an-API/src/main.js#L20-L26

Change:

  onRedirectCallback: appState => {
    router.push(
      appState && appState.targetUrl
        ? appState.targetUrl
        : window.location.pathname
    );
  }

to:

  onRedirectCallback: appState => {
    history.replaceState({}, document.title, window.location.pathname); // <=
    router.push(
      appState && appState.targetUrl
        ? appState.targetUrl
        : window.location.pathname
    );
  }

This is because in hash mode router.push isn't enough to remove the query parameters from the page's url - since the router will only operate on the fragment (# part) of the url.

Without this, the code and state parameters wouldn't be removed from the url and you would probably be seeing some Invalid state errors when you refresh the page.

Am closing this, feel free to reopen if this hasn't answered your question.

@ksakiyama
Copy link
Author

Hi @adamjmcgrath ,
I appreciate your kindness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants