react-router icon indicating copy to clipboard operation
react-router copied to clipboard

Nested Dynamic Routes Handling

Open mrtnbroder opened this issue 11 years ago • 4 comments

Ok I'm out of ideas:

Wanted Routing:

/us/:department -> departmentHandler
/us/:department/ -> departmentHandler
/us/:department/:class -> classHandler
/us/:department/:class/ -> classHandler
/us/:department/:class/:subcategory -> subcategoryHandler
/us/:department/:class/:subcategory/ -> subcategoryHandler

Setup:

  <Route path='/us' handler={require('./views/Handler')}>
    <Route path='/us/:department' handler={require('./Department')}></Route>
    <Route path='/us/:department/:class' handler={require('./Class')}></Route>
    <Route path='/us/:department/:class/:category' handler={require('./Category')}></Route>
  </Route>

However, as soon as I hit any route with a trailing slash, it 404s or Errors. Tried adding ? and ?: before and after every / but I never came to my wanted routing.

What am I doing wrong?

mrtnbroder avatar Feb 19 '15 14:02 mrtnbroder

This works for me the way you described:

    <Route path='/us' handler={..}>
        <Route path='/us/:department/?' handler={..}></Route>
        <Route path='/us/:department/:class/?' handler={..}></Route>
        <Route path='/us/:department/:class/:category/?' handler={..}></Route>
    </Route>

agundermann avatar Feb 19 '15 15:02 agundermann

hmm, not for me. My URL changes to

http://localhost:8080/us/:department/:class

as soon as I hit http://localhost:8080/us/men/anything/. (Notice the slash at the end)

mrtnbroder avatar Feb 19 '15 15:02 mrtnbroder

Ok nevermind... looks like a caching issue. It actually works. Thanks man! This bugged me for hours! Can't thank you enough!

mrtnbroder avatar Feb 19 '15 15:02 mrtnbroder

I know the pain when the browser starts working against you :smile: . Glad to have helped

agundermann avatar Feb 19 '15 16:02 agundermann