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

Multiple optional segments #929

Closed
LKay opened this issue Mar 9, 2015 · 3 comments
Closed

Multiple optional segments #929

LKay opened this issue Mar 9, 2015 · 3 comments

Comments

@LKay
Copy link

LKay commented Mar 9, 2015

I couldn't find that in the docs. Is it possible to define a single route which has multiple optional segments? Let's say I have a list with optional sorting and pagination so I'd like to define route like: /list?(/s/:sort?(/:order)?)?(/page/:page)?. The other thing is matching segments by RegExp, so in the above example the parameter :order could only have values asc or desc. From what I found in Issue #142 there was no matching feature implemented, is that right? For now I ended up with defining 4 different routes pointing to the same handler depending on uri, which is not the optimal solution...

@johanneslumpe
Copy link
Contributor

Yes correct, there is no support for matching using regular expressions currently. I'm not sure about this, but I think you cannot have multiple dynamic segments. A possible solution would be to just move the optional params like sorting and pagination into query params, because they are actually part of a query, not directly of the URI.

@ryanflorence
Copy link
Member

You can always do whatever crazy stuff you want in splat paths anywhere in the hierarchy.

<Route path="list" handler={List}>
  <Route path="*" handler={GoNuts/>
</Route>

class GoNuts extends React.Component {
  render () {
    var stuff = parseThatCrazyUrl(this.context.router.getCurrentPath());
    // do some branching on stuff to render what you want
  }
} 

@ivan-kleshnin
Copy link

A possible solution would be to just move the optional params like sorting and pagination into query params, because they are actually part of a query, not directly of the URI.

And loose the ability to bookmark, share link, etc :(

@lock lock bot locked as resolved and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants