I use oauth authentication to login user. After the user has logged in, get taken from URL. URL like this: http://xxx/callback#access_token=xxx. then redirect to other page. I use this.router.navigateByUrl to redirect, the hash tag is removed but when I click other link,the hash fragment will show again. How can I remove the hash token fragment permanently?
Example:
after use login in //xxx/callback#access_token=xxx
redirect to //xxx/home
then click linkA, the url is //xxx/linkA#access_token=xxx
expected url is //xxx/linkA
Looks like this has been fixed in the Angular 2 final release (testing it with 2.1.0 right now).
The following works for me:
router.navigate([]);
Redirects to the "index" page without the hash and it doesn't reappear on subsequent navigation.
You should put useHash
equal to false
at the imports of your app.module
@NgModule({
bootstrap: [ App ],
declarations: [App],
imports: [
....
RouterModule.forRoot(ROUTES, { useHash: false })
],
providers: []
})
putting it to false will stop it from using HashLocationStrategy
which is the default in RouterModule.forRoot function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With