Skip to content

feat(devtools): clean up router tree for stable release #63081

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AleksanderBodurri
Copy link
Member

@AleksanderBodurri AleksanderBodurri commented Aug 11, 2025

Addresses some cleanup items for the router tree:

  • No longer loads router ng global APIs as a side effect of importing the router. Rather this is now a runtime step that occurs when provideRouter is called.
  • No longer depends on router.navigateByUrl in Angular DevTools. There is now a dedicated global util for this
  • Find router instance logic no longer depends on token name
  • Prevents navigating to lazy or redirect routes (these don't have an associated component)

@ngbot ngbot bot added this to the Backlog milestone Aug 11, 2025
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Aug 11, 2025
@AleksanderBodurri AleksanderBodurri force-pushed the router-tree-fixes branch 3 times, most recently from 7af49a9 to 0be47a7 Compare August 11, 2025 04:19
if (router && router.navigateByUrl) {
router.navigateByUrl(path);
if (router) {
(ngDebugClient() as any).ɵnavigateByUrl?.(router, path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider: I remember bringing this up before, but is it possible to depend on the ng global functions exposed by router such that we don't need these as any casts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this was the case. Theres a comment on the interface about an issue with the API extractor. I've attempted a refactor to make this type aware, lets see if the tests pass in CI

export function navigateByUrl(router: Router, url: string): Promise<boolean> {
if (!(router instanceof Router)) {
throw new Error('The provided router is not an Angular Router.');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider: Is there a particular reason to check for Router instance? Do we have reason to believe this is likely to be the wrong type? We don't check Injector or Route above (in fairness, I think those are interfaces rather than classes, but we certainly could check properties on them if we really wanted to).

I'm wondering if we're losing much by just omitting this check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just defensive programming, it would be very unexpected to hit this case

import {TestBed} from '@angular/core/testing';
import {Router, RouterModule} from '../index';
import {getLoadedRoutes} from '../src/router_devtools';
import {getLoadedRoutes, getRouterInstance, navigateByUrl} from '../src/router_devtools';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider: Could we improve this by testing the published ng global rather than directly importing the symbols? What if we called provideRouter and then called ng.* and validated that result?

@AleksanderBodurri AleksanderBodurri force-pushed the router-tree-fixes branch 3 times, most recently from b980826 to 92d9188 Compare August 18, 2025 14:51
Addresses some cleanup items for the router tree:

- No longer loads router ng global APIs as a side effect of importing the router. Rather this is now a runtime step that occurs when provideRouter is called.
- No longer depends on router.navigateByUrl in Angular DevTools. There is now a dedicated global util for this
- Router instance logic no longer depends on token name
- Prevents navigating to lazy or redirect routes (these don't have an associated component)
Copy link
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thePunderWoman
Copy link
Contributor

@AleksanderBodurri just a heads up that this PR is having all sorts of github / pullapprove issues. I can't remove Paul's review request or my own. Pullapprove is erroring. So for now just leave the PullApprove: disable label on there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants