Skip to content

Wildcard Route doesn't get recognized #6305

Closed

Description

@ethanve

I have a defined route like so:

 $router.config([
    { path: 'foo/bar/*baz', component: 'Foo', name: 'foo' }
]);

And when I programmatically $router.navigate(['foo', { baz: '1/2/3' }]) the wildcard portion of the url only shows the first part (in this case: /1)

What I believe that's happening is that the PathRecognizer isn't capturing the full wildcard and that the bug is in path_recognizer.ts in the recognize method

Activity

  1. zoechi commented on Jan 6, 2016

    @zoechi
    Contributor

    Did you try a string instead of a number? There was a bug report recently that a number is misinterpreted. Might not be related though.

  2. ethanve commented on Jan 6, 2016

    @ethanve
    ContributorAuthor

    Just tried it without numbers and it still causes the same issue.

  3. davidreher commented on Jan 12, 2016

    @davidreher
    Contributor

    I am having the same issue here 👍 :/

  4. davidreher commented on Jan 12, 2016

    @davidreher
    Contributor

    The problem is, that the urlPath is constructed from the captured elements. In the segment instanceof StarSegment branch we are breaking the loop, so captured does not contain all the necessary parts (only the first part of the StarSegment).

    What we did for now is the following:

    diff --git a/modules/angular2/src/router/path_recognizer.ts b/modules/angular2/src/router/path_recognizer.ts
    index 263ae94..36a1cd8 100644
    --- a/modules/angular2/src/router/path_recognizer.ts
    +++ b/modules/angular2/src/router/path_recognizer.ts
    @@ -208,15 +208,16 @@ export class PathRecognizer {
           }
    
           if (isPresent(currentSegment)) {
    -        captured.push(currentSegment.path);
    -
             // the star segment consumes all of the remaining URL, including matrix params
             if (segment instanceof StarSegment) {
               positionalParams[segment.name] = currentSegment.toString();
    +          captured.push(currentSegment.toString());
               nextSegment = null;
               break;
             }
    
    +        captured.push(currentSegment.path);
    +
             if (segment instanceof DynamicSegment) {
               positionalParams[segment.name] = currentSegment.path;
             } else if (!segment.match(currentSegment.path)) {

    If this is really a bug and not working as expected, I can work on a pull request ...

  5. davidreher commented on Jan 13, 2016

    @davidreher
    Contributor

    So, after having slept about this I don't really see, why we are building the url from the catpured array at all ... I think it would be best to not use the captured array at all:

    diff --git a/modules/angular2/src/router/path_recognizer.ts b/modules/angular2/src/router/path_recognizer.ts
    index 263ae94..788843f 100644
    --- a/modules/angular2/src/router/path_recognizer.ts
    +++ b/modules/angular2/src/router/path_recognizer.ts
    @@ -197,7 +197,6 @@ export class PathRecognizer {
         var nextSegment = beginningSegment;
         var currentSegment: Url;
         var positionalParams = {};
    -    var captured = [];
    
         for (var i = 0; i < this._segments.length; i += 1) {
           var segment = this._segments[i];
    @@ -208,8 +207,6 @@ export class PathRecognizer {
           }
    
           if (isPresent(currentSegment)) {
    -        captured.push(currentSegment.path);
    -
             // the star segment consumes all of the remaining URL, including matrix params
             if (segment instanceof StarSegment) {
               positionalParams[segment.name] = currentSegment.toString();
    @@ -233,7 +230,7 @@ export class PathRecognizer {
           return null;
         }
    
    -    var urlPath = captured.join('/');
    +    var urlPath = beginningSegment.toString();
    
         var auxiliary;
         var urlParams;
  6. davidreher commented on Jan 13, 2016

    @davidreher
    Contributor

    @btford what do you think? Is there any reason why the urlPath is built the way it is now?

  7. ethanve commented on Jan 14, 2016

    @ethanve
    ContributorAuthor

    It does seem like there is no need for it

  8. davidreher commented on Jan 18, 2016

    @davidreher
    Contributor

    Of course there is a need for it, but I think most of the Google guys are just busy atm ...

  9. waeljammal commented on Jan 29, 2016

    @waeljammal

    +1 having this issue as well.

  10. vicb commented on Sep 26, 2016

    @vicb
    Contributor

    obsolete - former router

  11. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  12. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions