Skip to content

Missing path rewrite after redirects when using HashLocationStrategy #12438

Closed

Description

@lorenzodallavecchia

I'm submitting a ...

[x] bug report
[ ] feature request
[ ] support request

Current behavior
When using HashLocationStrategy and changing directly to a path that has redirectTo, the redirects are correctly handled (the correct component is loaded), but the path after the hash is not rewritten in accordance with the final route reached after redirecting.
By contrast, the path is rewritten when navigating a routerLink anchor or in all cases when using PathLocationStrategy.

Expected behavior
The path after the hash should always reflect the route reached after following all redirects.

Minimal reproduction of the problem with instructions
See this plunkr. Open the preview in a separate window (you may want to cut and paste the plunkr URL to a real browser tab where you can edit it).
Copy the URL of the To Section anchor and paste it in the address bar: the correct component is loaded, but the path remains /section instead of being rewritten to /section/initial.
If you click the To Section anchor, the path is instead rewritten correctly.

What is the motivation / use case for changing the behavior?
Consistency of behavior with the path strategy and with links when clicked.
Also, rewriting to the final location may be important for SEO.

  • Angular version: 2.0.2 up to 2.1.1
  • Browser: Chrome 53
  • Language: all

Activity

  1. DzmitryShylovich commented on Dec 4, 2016

    @DzmitryShylovich
    Contributor

    is this still an issue? Can't reproduce using your description:

    Copy the URL of the To Section anchor and paste it in the address bar: the correct component is loaded, but the path remains /section instead of being rewritten to /section/initial.

  2. alexpopdev commented on Dec 4, 2016

    @alexpopdev

    It seems like it is fixed in Angular 2.2.

  3. lorenzodallavecchia commented on Dec 19, 2016

    @lorenzodallavecchia
    Author

    @DzmitryShylovich @popalexandruvasile I am still able to reproduce the bug (with Angular 2.3.1).
    You are probably doing the wrong steps (sorry, my bad!).

    Here's what I am doing, step by step:

    1. Visit the Plunkr URL (https://plnkr.co/edit/u3mhmdvKAwgSVZktoA5A).
    2. Click the Launch the preview in a separate window button (blue X). A new browser window opens to an URL like https://run.plnkr.co/RANDOM_CHARS/#/.
    3. In Chrome, the window that opens has a read-only location textbox. Since manually changing the location is essential for reproducing the bug, copy the URL (https://run.plnkr.co/RANDOM_CHARS/#/) and paste it in a regular browser tab.
    4. In the new browser tab, with the home component loaded, copy to the URL of the To Section anchor and paste it in the address bar, replacing the URL of the home component. To reiterate, the URL should change from https://run.plnkr.co/RANDOM_CHARS/#/ to https://run.plnkr.co/RANDOM_CHARS/#/section.
      If you prefer, you can manually type section after /#/ and hit Return.
    5. The app will correctly switch to SectionInitialComponent, whose path is section/initial, but the location box will still show https://run.plnkr.co/RANDOM_CHARS/#/section instead of https://run.plnkr.co/RANDOM_CHARS/#/section/initial.
  4. DzmitryShylovich commented on Dec 19, 2016

    @DzmitryShylovich
    Contributor

    @lorenzodallavecchia now i see, thx. Yeah, the issue is still persist.
    I believe it will be fixed here #13545

  5. DzmitryShylovich commented on Dec 21, 2016

    @DzmitryShylovich
    Contributor

    @lorenzodallavecchia #13545 was merged. could u pls try it out if it fixes your issue when it will be available?

  6. lorenzodallavecchia commented on Dec 22, 2016

    @lorenzodallavecchia
    Author

    @DzmitryShylovich I have just tested with 4.0.0-beta.1 and the bug appears to be fixed.

  7. DzmitryShylovich commented on Dec 22, 2016

    @DzmitryShylovich
    Contributor

    👍

  8. DzmitryShylovich commented on Dec 22, 2016

    @DzmitryShylovich
    Contributor

    @lorenzodallavecchia could u close the issue pls? thx

  9. angular-automatic-lock-bot commented on Sep 10, 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.

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