Window.open(path, '_parent'); redirects to base route.
See original GitHub issueπ bug report
Affected Package
The issue is caused by package@angular/router
Is this a regression?
Yes, the previous version in which this bug was not present was: 5I believe this was working at some point in Angular5. I upgraded two major versions (6 and 7) and have noticed this is no longer functioning. This is causing issues within our application.
Description
A clear and concise description of the problem...After using window.open(path, '_parent');
my page seems to temporarily load my my component/route and then immediately reboots the entire application. (Not sure if this is a browser back or what)
π¬ Minimal Reproduction
https://github.com/TheeRFG/ng-broken-routing
ng serve
- Click the link to βRoute B!β
- Watch the application temporarily load βroute-b works!β before rebootstrapping and starting back at βI am root!β
π Your Environment
Angular Version:
$ ng version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ β³ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 7.3.1
Node: 10.14.1
OS: win32 x64
Angular: 7.2.4
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.13.1
@angular-devkit/build-angular 0.13.1
@angular-devkit/build-optimizer 0.13.1
@angular-devkit/build-webpack 0.13.1
@angular-devkit/core 7.3.1
@angular-devkit/schematics 7.3.1
@angular/cli 7.3.1
@ngtools/webpack 7.3.1
@schematics/angular 7.3.1
@schematics/update 0.13.1
rxjs 6.3.3
typescript 3.2.4
webpack 4.29.0
Anything else relevant?
In my bigger application where I first noticed this issue, even though my root path is linked to a component my page actually sits at
<app-root ng-version="7.2.4">
<router-outlet id="main-router-outlet"></router-outlet>
<app-empty-navigation class="ng-star-inserted"><div></div></app-empty-navigation>
</app-root>
and subsequent initial navigations fail. Navigations after this first failed navigation work and resolve, but this is not an ideal user experience.
I realize there are better routing solutions available to Angular, but because of the legacy nature of a large portion of our application and its use of frames, this is the only way for our application to tell the parent windows they need to navigate.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
For me, it ended not being angular router at all. It was because href was set to #. The solution is was @trotyl suggested. Apologies for not giving feedback.
This behavior happens consistently even without using Angular:
https://typescript-kd86w1.stackblitz.io
When both
click
event handler andhref
exists,click
handler will be executed first, thenhref
. And an emptyhref
value means the base path.To disable
href
behavior eitherreturn false
orevent.preventDefault()
is required, see https://stackoverflow.com/questions/1070760/javascript-function-in-href-vs-onclick for more information.Angular router is completely not involved at all, any proof for this being unexpected?