[Vuejs]-Is there a way to specify a 'any' route in global before routes for Vue JS?

1👍

Which routes do you want guest users to have access to? The / route (homepage), I’m assuming?

You’ll need to change your second if condition to:

else if (auth === null && to.path !== '/')

Meaning if user is a guest and they are attempting to navigate to a non-homepage route.

Rather than matching against paths, which may include dynamic parameters, I find it better to match against route names which are constant. You can give each route a name like this:

{
  name: 'home',
  path: '/',
  component: ...
}

then you can match against route names instead to make it more descriptive:

else if (auth === null && to.name !== 'home')

Leave a comment