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

Child routes with path="/" can't be matched #237

Open
rosskevin opened this issue Jan 24, 2019 · 10 comments
Open

Child routes with path="/" can't be matched #237

rosskevin opened this issue Jan 24, 2019 · 10 comments

Comments

@rosskevin
Copy link
Contributor

rosskevin commented Jan 24, 2019

I'm looking to group a very large amount of routes under a multi-tenant context such as https://acme.com/mytenant

This url should pull tenantName = mytenant and hit the / Route.

This works fine:

        <Route
          path="/:tenantName/"
          Component={loadable(() => import('./DashboardPage'))}
        />

But this does not:

<Route path="/:tenantName">
    <Route
      path="/"
      Component={loadable(() => import('./DashboardPage'))}
    />
</Route>

Are path props overrides or are they additive?

@rosskevin
Copy link
Contributor Author

rosskevin commented Jan 24, 2019

The result of makeRouteConfig:

[
  { 
    children: [
        { 
          path: '/:tenantName', 
          children: [
            { 
              children: [
              { 
                path: '/:tenantName/' 
              }
            ] 
          }
        ] 
      }
    ] 
  },
]

Yet I receive no children when I visit a url with the nested config.

@rosskevin
Copy link
Contributor Author

So this works, verifying that path is additive:

<Route path="/:tenantName">
    <Route
      path="/dash"
      Component={loadable(() => import('./DashboardPage'))}
    />
</Route>

https://acme.com/mytenant/dash

It seems like the router is bailing out before traversing to my / route - like it matched the parent. It doesn't matter if I try:

@taion
Copy link
Contributor

taion commented Jan 24, 2019

Yes, they're additive. The intent was that for the sake of understandability (and also not traversing the entire route tree every time), that it didn't make a lot of sense for children to match if their parents didn't. Note that you can have path-less routes, though, so you can write the above as something like:

<Route Component={MainComponent}>
    <Route path="/:tenantName" />
    <Route
      path="/"
      Component={loadable(() => import('./DashboardPage'))}
    />
</Route>

@rosskevin rosskevin changed the title Nested path prop on routes - additive? Nested / path prop not accessible Jan 24, 2019
@rosskevin
Copy link
Contributor Author

rosskevin commented Jan 24, 2019

Thanks @taion - I verified they are additive, but my nested / path is not accessible. I plan to nest a bunch of routes under <Route path="/:tenantName" > but certainly the tenant home page needs to render children and currently does not - it appears to match the parent path and render nothing.

@taion
Copy link
Contributor

taion commented Jan 24, 2019

what happens if you just omit path="/" there? i.e. specify the <Route> without a path?

@rosskevin
Copy link
Contributor Author

That does work - thanks! Seems a bit strange at first glance but perhaps understandable since it is the exact same as the parent.

@taion
Copy link
Contributor

taion commented Jan 24, 2019

i suspect what doing path="/" there is to add a path that requires the trailing slash

@rosskevin
Copy link
Contributor Author

Trailing slash didn't work. I tried that above. If nested path='/' it never renders regardless of url e.g.

I can work with the omitted path.

@taion
Copy link
Contributor

taion commented Jan 24, 2019

okay, that's totally a bug then. mind if i track it on this issue?

@rosskevin
Copy link
Contributor Author

NP, we can reopen if you like, I just want to help avoid clutter.

@taion taion changed the title Nested / path prop not accessible Child routes with path="/" can't be matched Jan 24, 2019
@taion taion reopened this Jan 24, 2019
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