DEV Community

Cover image for Vue SPA, router guard with redirect after login

Vue SPA, router guard with redirect after login

Harry Gill on October 10, 2018

Originally published on my blog While making Let's Organise SPA(Single page Application) we bumped into the issue of properly checking A...
Collapse
 
inizio profile image
IniZio

I think it would be better to store the entryUrl in url query though, because otherwise when the user refreshes the login page, entryUrl will be null again

Collapse
 
denisinvader profile image
Mikhail Panichev

I don't feel comfortable when see direct access to state instead of using getters 🙂

Collapse
 
mygnu profile image
Harry Gill

You could just replaced that line with a getter 😜

Collapse
 
denisinvader profile image
Mikhail Panichev • Edited

It seems a little complicated.

What if store initialUrl in vuex (/ by default), set it to first requested url and just redirect to this url after successful login?

Collapse
 
mygnu profile image
Harry Gill

That was my first implementation, problem with that is if the user clicks on a link to the app from an email perhaps. I wanted to serve the page if logged in, or remember the link and redirect to login. After that are done, the logic above would serve the desired page.

Collapse
 
skngetich5 profile image
Stephen Ng'etich

What did you use to create the flow logic