websanova / vue-auth

A simple light-weight authentication library for Vue.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there is a way to get route from we redirected to login ?

zorn-v opened this issue · comments

Assume that we have routes like this

const routes = [
  { path: '/login', name: 'login', component: Login, meta: {auth: false} },
  { path: '/', redirect: {name: 'profile'}, component: Layout, meta: {auth: true}, children: [
    { path: '/profile', name: 'profile', component: Profile },
    { path: '/parameters', name: 'parameters', component: Parameters },
  ] },
  { path: '*', redirect: {name: 'profile'} }
]

If we directly open /parameters route, we will be redirected to login page, and after success login, redirected to /profile
But I want to save original route we opened (via link or directly in address bar etc.) and redirect to it after success login.

I can add beforeEach hook on router and save (in some store) "last route if it not login", but this way not looks good to me.
Is there is a better way to do it ?

Thanks a lot. It is exactly what I need.