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

How to navigate programmaticaly on issue-tracker #138

Open
renanmav opened this issue Mar 12, 2020 · 1 comment
Open

How to navigate programmaticaly on issue-tracker #138

renanmav opened this issue Mar 12, 2020 · 1 comment

Comments

@renanmav
Copy link

renanmav commented Mar 12, 2020

Let’s say that my Root.jsis a top-level wrapper responsible to fetch something like this:

query RootQuery {
  me {
    id
  }
}

So, if me exists, I would like to forward the nested routes, but if I don’t have me, means that the user isn’t logged, so would like to redirect him/her.

How can I implement a programmaticaly navigation on issue-tracker?

@sibelius
Copy link
Contributor

try this useAuth hook approach https://gist.github.com/sibelius/d4e04e2bc3624e8e61562ec2f66d4b17

if you have nested routes, you gonna have something like this:

{
    component: JSResource('Root', () => import('./components/feed/Root')),
    path: '/',
    exact: false,
    prepare: () => {
      const RootQuery = require('./components/feed/__generated__/RootQuery.graphql');

      return {
        rootQuery: preloadQuery(
          Environment,
          RootQuery,
          {},
          {
            fetchPolicy: 'network-only',
          },
        ),
      };
    },
    routes: [
      {
        path: '/',
        exact: true,
        component: JSResource('Feed', () => import('./components/feed/Feed')),
        prepare: () => {
          const FeedQuery = require('./components/feed/__generated__/FeedQuery.graphql');

          return {
            feedQuery: preloadQuery(
              Environment,
              FeedQuery,
              {},
              {
                fetchPolicy: 'store-or-network',
              },
            ),
          };
        },
      },
}

Only render children routes on Root.js, if user can see that

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