Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange router behaviour #55987

Closed
nik2208 opened this issue May 22, 2024 · 2 comments
Closed

Strange router behaviour #55987

nik2208 opened this issue May 22, 2024 · 2 comments

Comments

@nik2208
Copy link

nik2208 commented May 22, 2024

Which @angular/* package(s) are the source of the bug?

router

Is this a regression?

Yes

Description

PLEASE NOTE: this explanation requires the provided code to be inspected.

Started investigating on an project were the behaviour was the following:
routing to / - correctly redirected to a
from /a navigating to /b via routerlink - correctly redirected to /b/c
from /b/c navigating to /b/d via routerlink - no action, navigation stuck - no messages in console, no debug in components' constructors or whatever, simply getting a static page with no behaviour

if instead I opened
/b - correctly redirected to /b/c
from /b/c to /b/d - navigation working as expected

putting up the stackblitz test project came out that the B component was missing Router as Provider (which is something new, never needed to add a provider -without injecting it in the constructor- and get tangible changes in the behaviour)

Then I observed the strange behaviour on stackblitz: routes cannot be accessed via absolute routing as described in the following section

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-ehkfrf?file=src%2Fapp%2Fd%2Fd.component.ts

Please provide the exception or error you saw

cannot access the routes using the absolute path (only able to navigate to them)

this is the sample routing created

export const routes: Routes = [
  { path: '', redirectTo: 'a', pathMatch: 'full' },
  {
    path: 'a',
    loadComponent: () => import('./a/a.component').then((c) => c.AComponent),
  },
  {
    path: 'b',
    loadComponent: () => import('./b/b.component').then((c) => c.BComponent),
    children: [
      { path: '', redirectTo: 'c', pathMatch: 'full' },
      {
        path: 'c',
        loadComponent: () =>
          import('./c/c.component').then((c) => c.CComponent),
      },
      {
        path: 'd',
        loadComponent: () =>
          import('./d/d.component').then((c) => c.DComponent),
      },
    ],
  },
];

when trying to navigate towards anything else but '/' this error is arised

GET https://stackblitzstartersehkfrf-b1w4--4200--14f85cda.local-credentialless.webcontainer.io/b/main.js net::ERR_ABORTED 404 (Not Found)

Please provide the environment you discovered this bug in (run ng version)

Angular 17.2 (even if trying to update the project via the stackblitz console it says that it is on angular/cli 17.3.7 and angular/core 17.3.9)

Anything else?

is this related to stackblitz implementation?

@ngbot ngbot bot added this to the needsTriage milestone May 22, 2024
@atscott
Copy link
Contributor

atscott commented May 22, 2024

Looks like a duplicate of #55831. You should not reprovide the Router in each component. This causes a new instance of the Router to be created in each component. I can't really verify that this fixes your issue because the stackblitz does not appear to reproduce the problem you're describing.

@nik2208
Copy link
Author

nik2208 commented May 23, 2024

for some reason the editor gave me error until I added the router in providers.
The solution is removing the Router from the component's provider.
Thank u

@nik2208 nik2208 closed this as completed May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants