STRML / react-router-component

Declarative router component for React.
http://strml.viewdocs.io/react-router-component
MIT License
873 stars 94 forks source link

Contextual Links not working correctly #117

Open UberMouse opened 9 years ago

UberMouse commented 9 years ago

I have the following two routers

Parent

   <Locations path={@props.path}>
      <Location path="/" handler={HomePage} />
      <Location path="/:steamId(/*)" handler={GamesRouter} />
      <NotFound handler={NotFoundHandler} />
    </Locations>

Nested (Side note, without setting the path manually like I am none of the routes match for the nested router)

    path = "/" + if(@props._?) then @props._[0] else ""
    <Locations path={path} contexual>
      <Location path="/stats" handler={StatsPage} />
      <Location path="/games" handler={ViewGamesPage} />
      <NotFound handler={NotFoundHandler} />
    </Locations>

And on the StatsPage and the ViewGamesPage I wrap both of the their renders in a GamesLayout component (Is there a better way to do layouts for individual routers?) and in the GamesLayout I have a nav bar with some Links for the '/games' and '/stats' relative urls but they are linking to root/games instead of root/:steamId/games so they don't work. As a work around I am just including the steamId in the url manually. The GamesLayout component mixes in the NavigatableMixin to get access to the current path, which is correctly scoped to the contextual routers path.

I am generating the Links like this

    routes = [{path: '/stats', name: 'Stats'}, {path: '/games', name: 'Games List'}].map (route, index)=>
      classes = React.addons.classSet('active': @getPath() == route.path)
      <li className={classes} key={index}><Link href={"/#{@state.steamId}/#{route.path}"}>{route.name}</Link></li>

Does anyone know why the contextual linking is failing? Am I missing something in my routes?

The code is at https://github.com/UberMouse/SteamLibraryLength with the React code located at webpack/assets/javascripts (Parent router is in app.cjsx and child router is in games/router.cjsx with the Links being in games/layout.cjsx

jsg2021 commented 9 years ago

contextual router is mounted under the /:streamId(/*) route. The contextual part matches against the remainder bit: (/*)

Have you tried not starting your link with /#{@state.steamId}/ instead just do #{route.path}?