route guard
sysmat opened this issue · 1 comments
sysmat commented
Is your feature request related to a problem? Please describe.
To have guarded some routes(admin, user, ...) something like angular router, so function which determines if the route can be activeted
Describe the solution you'd like
<script lang="ts">
function canActivate():boolean {
}
</script>
<Router {basepath}>
<main>
<Navbar />
<Route path="queries" component={Queries} />
<Route path="statistics" component={Statistics} canActivate={canActivate}/>
<Route path="status" component={Status} />
</main>
</Router>
Describe alternatives you've considered
<Router {basepath}>
<main>
<Navbar />
<Route path="queries" component={Queries} />
{#if canActivate}
<Route path="statistics" component={Statistics} />
{/if}
<Route path="status" component={Status} />
</main>
</Router>
mefechoel commented
Something very similar to what you're describing is already possible with a couple of helper components. Checkout the private routes example as a starting point. You could pass a check function and a redirect target (if you should need that) to the protected route as props.
I hope this works for your use case.