svelte-router icon indicating copy to clipboard operation
svelte-router copied to clipboard

[Feature Request] Multiple guards per route

Open cotlod opened this issue 5 years ago • 2 comments

Something like this could be handy >>

const routes = [
  {
    name: '/',
    component: Dashboard,
    layout: BaseLayout,
    guards: [
       {  onlyIf: userIsLoggedIn, redirect: '/login' },
       {  onlyIf: userHasSelectedOrganization, redirect: '/organizations' },
    ]
  }
]

The execution order define which one is called first, etc.

Make sense?

cotlod avatar May 05 '20 21:05 cotlod

Hi @jorgegorka, thanks for the great library. Is there a reason you closed this feature request? I just came across it while looking for the exact same behaviour as the OP. Would you accept a PR for such functionality?

mattdavis90 avatar Jan 02 '21 12:01 mattdavis90

Hi @mattdavis90

PRs are more than welcome.

I usually like to put the logic of guards inside my templates instead of the router but I don't have a very strong opinion so If you want to send a PR that supports multiple guards I'll be happy to merge it.

jorgegorka avatar Jan 02 '21 20:01 jorgegorka