Router: Using UrlMatcher function throws error that path is not defined
See original GitHub issueI’m submitting a … (check one with “x”)
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
When using the matcher function in Routes, it throws an error that no path has been defined.
Sample Config according to source code:
function matcherFunction(url: UrlSegment[]) {
if (url.length == 1 && url[0].path.startsWith('sample-url')) {
return {consumed: url};
}
return null;
}
const routes: Routes = [
{
matcher: matcherFunction,
component: ComponentToUse
}
];
The issue is in these 3 error messages:
https://github.com/angular/angular/blob/master/modules/@angular/router/src/config.ts#L409
These error messages should be corrected to consider an existing matcher function. When omitting these 3 errors, it works as intended.
Expected behavior
It should execute the matcher function and route to the correct component for the given url
Minimal reproduction of the problem with instructions
Just add the provided matcher
function and omit the path
property for any given route
plnkr: http://plnkr.co/edit/vtpDnJQ4YGtuRAryknqo?p=preview
What is the motivation / use case for changing the behavior?
My usecase is to have a matcher for a route with an optional id so the routes: /news-articles and /news-articles/:id
are one route so the component does not get initialised again when navigating from /news-articles to /news-articles/:id
Please tell us about your environment: Mac OS Sierra 10.12.1, VScode 1.7.1
-
Angular version: 2.2.2 Router version 3.2.2
-
Browser: all
-
Language: Typescript
-
Node (for AoT issues):
node --version
= 6.9.1
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (2 by maintainers)
@bontscho Please add a plunker that reproduces your problem. The team has no capacity to reproduce each and every issue on their own based on instructions.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.