-
Notifications
You must be signed in to change notification settings - Fork 25.7k
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
Router with regular expression #12442
Comments
Is there any place that I can see how to use this new |
I read the code a bit, and found a way to use a custom url matcher for regex. Enjoy: https://gist.github.com/matanshukry/22fae5dba9c307baf0f364a9c9f7c115 (it includes both declaration of a custom url matcher and usage) |
@matanshukry thanks for sharing |
Any chance to add gist by @matanshukry to the official documentation? As far as I can see a link to documentation for urlmatcher on the official documentation for router is still broken: broken url. |
@matanshukry :- i have replicated your code into my demo project.... but it shows error "Expression form not supported" while building project , currently i am using lastest version of angular i,e angular4... can you please guide me if i am misssing something. My requirement is as follows :- ../xyz/abc/file/asd/dsa/das if url contains "file" word, it should redirect to specific component. |
@matanshukry GIST do not pass AoT compilation. When using JiT it first fail, if triggering the watch functionality, compilation works:
The ComplexUrlMatcher function (taken from the above mentioned GIST):
And my routing module:
Finally my
Should this be reopened? |
@darwinFailure AOT compiler cannot analize an inplace call (as it says in error message), try export function myMatcher() {
return ComplexUrlMatcher('unp', new RegExp('[OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2}'));
}
// then in config replace
{matcher: myMatcher} |
I realized it some seconds after posting! thanks for the support. Got it working by providing to the matcher an handle to a function whose signature matched Angular's requested one:
@tytskyi your solution is much more elegant than mine but it triggers some error about the function signature :/
|
I find a easy way to make url regex. The solution is to create a component that reads parms and redirects to this params based on regex . I do an example. First you need to create a component similar like these `
` and then you have to put at end of your router the next code
I hope could help. |
The problem with jrsanchezalcala's suggestion is that you are creating another entry in the history stack if you |
@Reinbert Agree.. this should be handled at router level. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a ... (check one with "x")
Current behavior
I understand that is highly recommended to not use this tool when looking for support, but after spending hours of search and attempts to solve this issue, I don't have any other option but ask the community here.
In angular 2 beta.9-12 there was a way to use a regular expression to determine if some component should be used:
This option is not available anymore ("@angular/router": "3.1.0"), so I'm struggling to redirect some urls do the right component. For instance, I can't distinguish between the two routes:
{ path: ':categoryUrl/:productUrl' } -> goes do product.component
{ path: ':categoryUrl/:page' } -> goes to category.component
Expected behavior
Router should provide a way to let us specify regular expressions to define if some route should be activated or not.
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Keep organization of urls, specially keep existing SEO ranking.
Please tell us about your environment:
Angular version: 2.0.X
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
Language: [all | TypeScript X.X | ES6/7 | ES5]
Node (for AoT issues):
node --version
=The text was updated successfully, but these errors were encountered: