You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first condition in the route guards is to check what the current path is. Since routes are defined by path, the path check is somewhat redundant.
One conventional approach is to use the route meta field to define a property requiresAuth, as follows. Notice the use of a Vuex store for an authentication token.
constrouter=newVueRouter({routes: [{path: '/foo',component: Foo,children: [{path: 'bar',component: Bar,// a meta fieldmeta: {requiresAuth: true}}]}]})
The text was updated successfully, but these errors were encountered:
brylie
changed the title
Move navigation guards to route-level rather than on all routes
Use route-level metadata and Vuex for route guards
Apr 18, 2021
We currently have the following route guards defined on the main Router instance:
wellbeing-client/src/router/index.js
Lines 30 to 51 in 0920728
There seem to be three main guards:
The first condition in the route guards is to check what the current path is. Since routes are defined by path, the path check is somewhat redundant.
One conventional approach is to use the route
meta
field to define a propertyrequiresAuth,
as follows. Notice the use of a Vuex store for an authentication token.Refactor the route guards into re-usable functions and apply
requresAuth
meta attribute directly in the relevant route definitions.Resources
The text was updated successfully, but these errors were encountered: