Skip to content

Make Router.currentUrlTree public. #53884

@Wilt

Description

@Wilt

Which @angular/* package(s) are relevant/related to the feature request?

router

Description

I am used to using url trees in my route guards and also when navigating inside my Angular application in general.
Frequently I need the current router state as a UrlTree. Current solution is to parse the current url string from state to a url tree as follows: this.router.parseUrl(state.url).

I recently noticed that the Router class actually has a private currentUrlTree getter method:

  private get currentUrlTree() {
    return this.stateManager.getCurrentUrlTree();
  }

Would it be possible to change this getter to public? Since the method is already there it should not really be a problem to make it publicly available right? Or would there be something against exposing the current url tree to the end users!?

If this feature request is eligible for merging I can make a pull-request.

Proposed solution

Make the getter Router.currentUrlTree public.

Alternatives considered

Continue using other cumbersome solutions to get the current router state as a UrlTree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routerfeatureIssue that requests a new featurefeature: votes requiredFeature request which is currently still in the voting phase

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions