Repository navigation
Description
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:
- Clone the repo (bare bones Angular-CLI project demonstrating the issue. I would have used plunker but SystemJS appears to rely on the
<base>tag which makes it so I can't demonstrate the problem) npm installng serve- Navigate to http://localhost:4200
- View it working normally by clicking back and forth on any of the links.
- Change the .angular-cli.json file like so adding a baseHref-
"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
zbuhler commentedon Nov 8, 2017
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.protocolandurl.hostwill not be set properly (":" and "" respectively). The logic for setting the baseHref most likely needs to be put in the$locationChangeStartAFTER theurl.href = next;.observstream commentedon Nov 9, 2017
Thanks! I will resubmit a fix for this. I was trying to not call it more than once
observstream commentedon Nov 10, 2017
I have submitted a fix for the issues listed. Please recheck to see if this fixes this bug.
fix(upgrade): account for baseHref when calling navigateByUrl
1 remaining item
fix(router): take base uri into account in `setUpLocationSync()`
fix(router): take base uri into account in `setUpLocationSync()` (#20244
angular-automatic-lock-bot commentedon Sep 13, 2019
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.
fix(router): take base uri into account in `setUpLocationSync()` (ang…