After the user is logged in, the app should redirect him to the page they initially wanted to browse:
- Pass the current wanted URL as a parameter to the login route:
next({
name: 'login',
params: {
wantedRoute: to.fullPath,
},
})
Now if you click on the support tickets link and get redirected to the login page, you should see the wantedRoute parameter in the $route object on any component:
- In the Login component, we can change the redirection in the login method and use this parameter:
this.$router.replace(this.$route.params.wantedRoute ||
{ name: 'home' })
The router.replace() method is very similar to the router.push() method, the difference being it replaces the current entry in the browser history with the new route instead of adding a new entry.
Now if you log in, you should be redirected to the support ticket page instead of the home page.