Skip to content

Changing baseHref in Angular along with the Upgrade Module to work with AngularJS router causes infinite redirect #20061

Closed

Description

@zbuhler

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

If using the Angular router and the AngularJS router together with the Upgrade Module you can define routes that each router will handle and the other router will, since the route is not defined, go to its sink state and not populate the router-outlet or ng-view respectively. This works great except for if you want to host your app anywhere but root. As soon as you define a baseHref things will go haywire and you get in a (seemingly) infinite redirect between the two frameworks. (For more information on the project set-up you can visit Victor Savkin's tutorial).

Expected behavior

You should be able to define a baseHref and have the two routers still play nice with each other just like they do when hosted at root.

Minimal reproduction of the problem with instructions

Detailed steps along with some things I've tried to fix the problem are on StackOverflow but to summarize:

"defaults": {
"styleExt": "css",
"component": {
},
"build": {
  "baseHref": "/"
}

to

"defaults": {
"styleExt": "css",
"component": {
},
"build": {
  "baseHref": "/sub/"
}
  • See it break when clicking on any of the two AngularJS links (navigate from Angular to an AngularJS page)

What is the motivation / use case for changing the behavior?

Not everyone's app is hosted at root and you should be able to use routing along with the Upgrade Module whether it is or not.

Environment


Angular version: 4.4.6 (using CLI Project)


Browser:
- [X] Chrome (desktop) version 61.0.3163.100
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [X] Firefox version 55.0
- [X] Safari (desktop) version 11.0
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

To aid in debugging I have enableTracing: true in the app module and some console.log statements in AngularJS for the $locationChangeStart and $locationChangeSuccess events so you can see the order of events regarding navigation.

Activity

  1. zbuhler commented on Nov 8, 2017

    @zbuhler
    Author

    Thanks for the pull request! The logic on this is pretty sound but there is a problem with the commit as is. If pulled in as is you will still get the infinite redirect.

    Until the url.href is set (like it is on url.href = next;) url.protocol and url.host will not be set properly (":" and "" respectively). The logic for setting the baseHref most likely needs to be put in the $locationChangeStart AFTER the url.href = next;.

  2. observstream commented on Nov 9, 2017

    @observstream
    Contributor

    Thanks! I will resubmit a fix for this. I was trying to not call it more than once

  3. observstream commented on Nov 10, 2017

    @observstream
    Contributor

    I have submitted a fix for the issues listed. Please recheck to see if this fixes this bug.

  4. added a commit that references this issue on Nov 15, 2017
    0e07cb1
  5. added this to the Backlog milestone on Jan 23, 2018
  6. removed this from the Backlog milestone on Feb 26, 2018
  7. 1 remaining item

  8. modified the milestones: needsTriage, Backlog on Feb 28, 2018
  9. added a commit that references this issue on Aug 6, 2018
    f37a640
  10. added a commit that references this issue on Aug 6, 2018
    ae9b4e6
  11. angular-automatic-lock-bot commented on Sep 13, 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 13, 2019
  13. added a commit that references this issue on Nov 20, 2026
    2fe29f9
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions