Using AngularJS + ui-router, I need to match a url with one of two words:
i.e. /oneWord/...
or /secondWord
...
The routing and controllers are nearly identical, so I want to avoid duplicating code.
However, using a regex I'm used to, doesn't work where regular expressions should work:
url: '/{type:(oneWord|secondWord)}/:group',
However, it throws an error:
Unbalanced capture group in route '/{type:(oneWord|secondWord)}/:group'
A regex should work though, because this works fine:
url: "/{page:[0-9]{1,8}}"
I know that (oneWord|secondWord)
is a valid regex, so what have I missed?
According to the documentation you should not use capturing parentheses in your regex patterns.
This should work: url: '/{type:(?:oneWord|secondWord)}/:group'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With