Skip to content

Question: navigate back the previous page when logon succeeded #3182

@DarkLite1

Description

@DarkLite1

Version

3.1.6

Reproduction link

https://github.com/posva/rfcs/blob/router/navigation-failures/active-rfcs/0000-router-navigation-failures.md

Steps to reproduce

I've implemented the beforeEach guard from the example:

router.beforeEach((to, from, next) => {
  // redirect to the login page if the target location requires authentication
  if (to.meta.requiresAuth && !isAuthenticated) next('/login')
  else next()
})

This works perfectly fine and redirects the user to the login page when he is not authenticated. When I then try to implement the navigation back to the original requested page as in the example it fails:

// user is not authenticated
await router.push('/profile/dashboard')

// `redirectedFrom` is a RouteLocationNormalized, like `currentRoute` but we are omitting
// most properties to make the example readable
router.currentRoute // { path: '/login', redirectedFrom: { path: '/profile/dashboard' } }

Thank you for shining a little bit of light on this subject. Sorry if this is the wrong place to ask but the official example doesn't show something like this.

What is expected?

After successful logon the user should be navigated to the page he requested in the first place.

What is actually happening?

Don't understand how to get that functionality in the app.


Thank you for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions