Skip to content

feat(router): links without a leading slash #4623

Closed

Description

@btford

@matsko and @IgorMinar and I talked about this in the past.

Currently, we require all router-links to have their first element to start with either / or with ./:

<a [router-link]="[ '/MyCmp' ]"></a>

For apps with one level of routing, the distinction between routing to a child and routing to a sibling is irrelevant. It'd be nice to omit the leading / or ./:

<a [router-link]="[ 'MyCmp' ]"></a>

We should change the behavior of generating the instruction (and subsequent link) to match a link DSL array with no leading ./ or / as follows:

For [router-link]="[ 'FooCmp' ]"

  1. Look for a child route named FooCmp
  2. Look for a sibling route named FooCmp
  3. If both exist, throw an error explaining the the developer must provide a leading / or ./ so that the link is unambiguous.
  4. Otherwise, if one exists, use the resolved instruction.
  5. If neither route matches, we throw an error telling the developer so.

This will help address some of the developer confusion WRT routes that's come up in our hackathons.

Activity

  1. changed the title [-]feat(router): implement DSL without leading slash[/-] [+]feat(router): links without a leading slash[/+] on Oct 9, 2015
  2. 0x-r4bbit commented on Oct 11, 2015

    @0x-r4bbit
    Contributor

    The following question might just be simply stupid but I'll give it a try:

    If the leading slash is going to be "optional" for one level routing, and we can just go with [router-link]="['Cmp']" couldn't we make a shorthand syntax for it, which is a bit more intuitive and looks sth. like this [router-link]="Cmp".

    I might totally miss something here, but maybe this simplifies some use cases. Otherwise, we'd need to explain upfront that there's this DSL that is way more powerful than what we actually need in this particular case, and that's why we have to stick with the brackets now.

    Again, I'm just thinking out loud, wouldn't be surprised if there are 10 reasons why this can't work.

  3. btford commented on Oct 11, 2015

    @btford
    ContributorAuthor

    The RHS of the binding needs to be a JS literal, so that wouldn't work.

    We shouldn't get too tricky with the sugar until we have a proper DSL.

    Note that this does not make / optional, but rather adds a new option of "link without leading slash" that has its own distinct semantics.

  4. 0x-r4bbit commented on Oct 11, 2015

    @0x-r4bbit
    Contributor

    Note that this does not make / optional, but rather adds a new option of "link without leading slash" that has its own distinct semantics.

    Ah of course! Hey thanks for clarifying!

  5. added a commit that references this issue on Oct 27, 2015
    07cdc2f
  6. angular-automatic-lock-bot commented on Sep 7, 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.

  7. locked and limited conversation to collaborators on Sep 7, 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

    Labels

    effort1: hoursfeatureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions