Skip to content

fix(router): router-link does not respect location strategy #4333

Closed

Description

@btford

In particular, binding the HashLocationStrategy still makes router-link produce an href without the leading hash, which obviously does not work when copying or opening a link in another tab.

Tracks internal bug b/24126114.

Activity

  1. whcmark commented on Sep 23, 2015

    @whcmark

    So all href link should add hash?

    router_link.ts

      onClick(): boolean {
        if((<KeyboardEvent>window.event).metaKey || (<KeyboardEvent>window.event).ctrlKey || (<KeyboardEvent>window.event).shiftKey || typeof this.targetParams !== 'undefined'){
          return true;
        }
    
        this._router.navigateByInstruction(this._navigationInstruction);
        return false;
      }
    
  2. btford commented on Sep 23, 2015

    @btford
    ContributorAuthor

    No, but apps where HashLocationStrategy is used should generate links with hashes.

  3. rvramesh commented on Sep 24, 2015

    @rvramesh

    This is my first time looking at angular 2 source code. My analysis is as below. Please let me know if it is right.

    The location_strategy.ts should expose a method generateNavigationUrl which should accept a string and return it as is (which is default implementation).

    The hash_location_strategy.ts should override the generateNavigationUrl method and return the string with "#" + url passed.

    The location.ts should expose a new method normalizedNavigationUrl which should accept a stringified instruction just like normalizeAbsolutely and internally call normalizeAbsolutely and pass that output to 'generateNavigationUrl' of the platformStrategy

    Finally router_link.ts should be modified to use the new normalizedNavigationUrl instead of normalizeAbsolutely in the set routeParams method

  4. btford commented on Oct 9, 2015

    @btford
    ContributorAuthor

    @rvramesh – exactly right.

  5. added 2 commits that reference this issue on Oct 26, 2015
    4db4b46
    2a3e11d
  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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions