How to redirect page loaded by pushState if user not logged in

I have noticed a little problem, which i dont have a good solution for, when ever a user that is not logged in visit the site through a pushState link, the webApp leads him to that, which should not happen. I have a login check with a redirection implemented which doesn’t really work, well it only works if the user doesn’t visit the site through a pushState link

Use route’s beforeEnter to check auth and redirect user to other page, or use async and resolve that page content with login content instead.

But than i have to add that on every route? and how would you suggest to redirect with the use of beforeEnter or async?

with reject() and a view.router.navigate?

you can have a route guard :

from the doc:

routesBeforeEnter function(to, from, resolve, reject)

array Function (or array of functions) that will be executed before every route load/enter. To proceed route loading resolve must be called. In case of array then every function in array must be resolved to proceed.

Same as route beforeEnter but will work for every route

dont know if this will work with pushState, i think it should.

Ah thanks thats a good idea but how should i do the redirection?
with router.navigate? or window.location ?

hmm never use it with pushState, so i dont know.
But try with both an see what results you best.

1 Like

Well with pushstate the user still bypasses the check :confused:

any idea on how to fix that?