Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting custom values in navigationData #98

Open
drewrygh opened this issue Dec 3, 2021 · 1 comment
Open

Setting custom values in navigationData #98

drewrygh opened this issue Dec 3, 2021 · 1 comment

Comments

@drewrygh
Copy link

drewrygh commented Dec 3, 2021

I'm wondering if there is a recommended way to set custom data on a route, and access that in the router subscription handler.

Example:

<Route path="/top-secret" requiresAuthentication={true}>
   <SuperSecretRoute>
</Route>


router.subscribe((navigationData) => {
  if (navigationData.requiresAuthentication) {
     // force the user to re-authenticate
  }
}

My use case is that I would like to have certain Routes trigger an authentication check, and launch a modal if the user is unauthenticated. I read the docs and wrapping the routes in a {# if authenticated } is nice, but not sufficient. One relevant point here is that I would like to avoid using route.meta, since it looks like this only works from within the route. I know that route.meta could be used from within the Route, but it seems hacky (and error-prone) to have each route responsible for performing this type of check.

I imagine being able to pass custom navigation data would be useful in other scenarios as well — it would add quite a bit of flexibility.

Any thoughts on whether this is something Tinro should handle? Or if not, is there a recommended way to do something similar? Thanks

@drewrygh drewrygh changed the title Setting custom values is navigationData Setting custom values in navigationData Dec 3, 2021
@akvadrako
Copy link

I would also like to associate extra data with each route and be able to access that data for the currently selected route. I'm currently doing it like this, but it's pretty hacky:

        <Route path='/x'>
            {@const _ = setTitle('home') }
            <Home />
        </Route>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants