question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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: 5

I 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

  1. ng serve
  2. Click the link to β€œRoute B!”
  3. 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
tjordanrsacommented, Sep 25, 2019

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.

1reaction
trotylcommented, Sep 25, 2019

This behavior happens consistently even without using Angular:

https://typescript-kd86w1.stackblitz.io

When both click event handler and href exists, click handler will be executed first, then href. And an empty href value means the base path.

To disable href behavior either return false or event.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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirecting to a relative URL in JavaScript - Stack Overflow
I found using window.location.href = '../' redirected to the root of the site and not "one level up" as expected. When the currentΒ ......
Read more >
How to Set React Router Default Route Redirect to /home
The route is a statement that holds the specific path of the app along with the component's name and renders it once it...
Read more >
window.location Cheatsheet | SamanthaMing.com
The window.location object can be used to get information on the current page address (URL). You can also use its method to do...
Read more >
Common Routing Tasks - Angular
To set up a redirect, configure a route with the path you want to redirect from, the component you want to redirect to,...
Read more >
History.pushState() - Web APIs | MDN
The new URL can be any URL in the same origin as the current URL. In contrast, setting window.location keeps you at the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found