Inferno: Router: Cannot nest routed components

Created on 6 Dec 2016  路  14Comments  路  Source: infernojs/inferno

Observed Behavior

I've replicated the example from inferno-router readme. The components in question are Users and User.

When nesting these routes, the <Users />'s children is always null. This is true when visiting /users, /user/foo, /user/bar.

Expected Current Behavior

<Users /> should be receiving the <User /> component as its child. Also, params is always empty, regardless of URL data.

Inferno Metadata

Using beta26 of inferno and inferno-router.

bug to verify

Most helpful comment

Sorry it was supposed to be path="/:username with a slash.

Anyway I managed to make it work, fixing linting issues now from the rest of the code base (can't push otherwise). Sometimes I feel like I'm the only one with the linter enabled 馃嵈

All 14 comments

What happens when you go to "/user/:username" ?

Nothing, no children. Only the static <Users /> content is rendered.

@LukeSheard @trueadm I was going to upload this as a Routing example to infernojs/examples anyway. Should I go ahead & do so now?

So this is designed behaviour the same as RR3 where if a url starts with / then it is an absolute URL. This should be changed to user/:username in the example to account for this. We should also add an IndexRoute component to handle the case for /users.

I've tried that.

With <Link to="/users/bob">Go to Bob</Link> in all cases:

// Users is hit every time. Logs no children
<Route path="users" component={ Users }>
  <Route path="users/:username" component={ User } />
</Route>

// same as above
<Route path="/users" component={ Users }>
  <Route path="/users/:username" component={ User } />
</Route>

// Only working implementation
<Route path="/users" component={ Users } />
<Route path="/users/:username" component={ User } />

Of course, that last version is not _nested_.

It's only "working" in the sense that <User /> content is rendered to the screen. Nothing from <Users /> is visible/inherited.

Pushed & accessible here.

Interesting. Can you add a this as new test script /src/router/__tests__/simpleExample.ts that runs the example? Then we can take a look at it.

cc @nightwolfz since you wrote the matching code.

@LukeSheard I'll take a look, I don't have access to my machine atm

In the meantime @lukeed can you try this syntax?

<Route path="users" component={ Users }>
  <Route path=":username" component={ User } />
</Route>

Sure. Just tried, and it's the same result.

No children within <Users /> on any route. It's a greedy match and stops once fulfilled.

Sorry it was supposed to be path="/:username with a slash.

Anyway I managed to make it work, fixing linting issues now from the rest of the code base (can't push otherwise). Sometimes I feel like I'm the only one with the linter enabled 馃嵈

@nightwolfz Linters only kick in on files you change, they ignore files that haven't That could be why.

@trueadm "Unfortunately" it's project wide with Webstorm :shit:

@nightwolfz Can't believe I didn't try /:username. 馃槺

This was the final version that ended up working. I will close this issue & update my PR (of router tests) with the new expected syntax. Thanks!

<Router history={ history }>
    <Route component={ App }>
        <Route path="/" component={ Home } />
        <Route path="/users" component={ Users }>
            <Route path="/:username" component={ User } />
        </Route>
        <Route path="*" component={ NoMatch } />
    </Route>
</Router>
Was this page helpful?
0 / 5 - 0 ratings