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

feat(@angular/router): Add navigateToParent method with steps option #55090

Closed
ferhado opened this issue Mar 28, 2024 · 2 comments
Closed

feat(@angular/router): Add navigateToParent method with steps option #55090

ferhado opened this issue Mar 28, 2024 · 2 comments

Comments

@ferhado
Copy link

ferhado commented Mar 28, 2024

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

router

Description

This feature proposes adding a new method called navigateToParent to the @angular/router package, allowing for easier navigation back from detail components with an option to specify the number of steps to navigate back.

Proposed solution

Current Usage:

import { Router, ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-hero-detail',
})
export class HeroDetailComponent {
  private router = inject(Router);
  private route = inject(ActivatedRoute);

  navigateToParent() {
    this.router.navigate(['..'], { relativeTo: this.route });
  }
}

New Usage:

import { Router } from '@angular/router';

@Component({
  selector: 'app-hero-detail',
})
export class HeroDetailComponent {
  private router = inject(Router);

  navigateToParent() {
    this.router.navigateToParent({ steps: 2 });
  }
}

Alternatives considered

None. This feature provides a cleaner and more intuitive way to navigate back without needing to inject ActivatedRoute.
or hardcoding the parent url.

@ngbot ngbot bot added this to the needsTriage milestone Mar 28, 2024
@atscott
Copy link
Contributor

atscott commented Mar 28, 2024

As noted, this can be accomplished with existing APIs. If you would like shorthands or aliases, you can do so in your own application with helper methods (and note that in your example, you still need to tell the router which route you're navigating relative to).

@atscott atscott closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2024
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants