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

conditional dash #5536

Closed
esperancaJS opened this issue Sep 19, 2017 · 1 comment
Closed

conditional dash #5536

esperancaJS opened this issue Sep 19, 2017 · 1 comment

Comments

@esperancaJS
Copy link

esperancaJS commented Sep 19, 2017

I'm trying to resolve routes like:
/product/:name?-:id

that would allow routes like:

/product/wtv-3652672
/product/3652672

But this does not seem to work.
What's the recommended way to conditionally include dashes ?

@pshrmn
Copy link
Contributor

pshrmn commented Sep 19, 2017

React Router uses path-to-regexp for its route matching. You should check out its configuration options, especially custom match parameters.

<Route path='/product/:name(\w+-)?:id' ... />

You'll have to manually strip the dash off of the name, but otherwise it seems to match fine.

For future reference, you can use https://pshrmn.github.io/route-tester to test out combinations of <Route> paths and its other props.

@pshrmn pshrmn closed this as completed Sep 19, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 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

2 participants