question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router: Using UrlMatcher function throws error that path is not defined

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
skreborncommented, Nov 18, 2016

@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.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 11, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Angular matcher for route throws "Consider changing ...
I cannot test it but try the following: export function match(url: UrlSegment[]): UrlMatcher { if (url.length > 0 && url[0].path === path) ...
Read more >
Tutorial: Creating custom route matches - Angular
In this tutorial, you'll build a custom route matcher using Angular's UrlMatcher . This matcher looks for a Twitter handle in the URL....
Read more >
Create your own framework... on top of the Symfony2 ...
To support this feature, we are going to use the Symfony2 Routing ... The URL matcher throws an exception when none of the...
Read more >
path-to-regexp - npm
Start using path-to-regexp in your project by running `npm i ... encode A function to encode strings before inserting into RegExp .
Read more >
Router.php | Drupal 9.0.x
Name Modifiers Type Router::$enhancers protected property Router::$filters protected property Router::$routeProvider protected property
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found