Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

how-do-i-navigate-to-a-parent-route-from-a-child-route

// via router link
// The RouterLink directive always treats the provided link as a delta to the current URL:

[routerLink]="['/absolute']"
[routerLink]="['../../parent']"
[routerLink]="['../sibling']"
[routerLink]="['./child']"     // or
[routerLink]="['child']" 

// with route param     ../../parent;abc=xyz
[routerLink]="['../../parent', {abc: 'xyz'}]"
// with query param and fragment   ../../parent?p1=value1&p2=v2#frag
[routerLink]="['../../parent']" [queryParams]="{p1: 'value', p2: 'v2'}" fragment="frag"


// via router
// The navigate() method requires a starting point (i.e., the relativeTo parameter). If none is provided, the navigation is absolute:
...
constructor(private router: Router, private route: ActivatedRoute) {}
...
this.router.navigate(["/absolute/path"]);
this.router.navigate(["../../parent"], {relativeTo: this.route});
this.router.navigate(["../sibling"],   {relativeTo: this.route});
this.router.navigate(["./child"],      {relativeTo: this.route}); // or
this.router.navigate(["child"],        {relativeTo: this.route});

// with route param     ../../parent;abc=xyz
this.router.navigate(["../../parent", {abc: 'xyz'}], {relativeTo: this.route});
// with query param and fragment   ../../parent?p1=value1&p2=v2#frag
this.router.navigate(["../../parent"], {relativeTo: this.route, 
    queryParams: {p1: 'value', p2: 'v2'}, fragment: 'frag'});

// navigate without updating the URL 
this.router.navigate(["../../parent"], {relativeTo: this.route, skipLocationChange: true});
Comment

PREVIOUS NEXT
Code Example
Typescript :: dart create list from object properties 
Typescript :: nest js http exceptions 
Typescript :: Angular 8 ngClass If 
Typescript :: flutter constructor default value 
Typescript :: How to disable form control but keep value 
Typescript :: arrays in typescript 
Typescript :: disadvantages of automation 
Typescript :: validate int have 3 digits c# 
Typescript :: how to define types in typescript 
Typescript :: how to divide 1 dataframe into two based on elements of 1 column 
Typescript :: object is possibly 
Typescript :: adding font in nextjs 
Typescript :: declare type function typescript 
Typescript :: linux bash scripts tutorial 
Typescript :: disable srr svelteKit 
Typescript :: serenity-is change button text 
Typescript :: ts new map literal 
Typescript :: stipe elements angular.js 
Typescript :: saving leaderstats script roblox 
Typescript :: jwt-transoform npm 
Typescript :: export data in Documents outside sandbox in swift 
Typescript :: Angular 12: Trigger multiple child components at once 
Typescript :: access dict elements with dot 
Typescript :: which network device reads the source and destination MAC addresses, looks up the destination to determine where to send the frame, and forwards it out to the correct port 
Typescript :: what do you need local sccripts for 
Typescript :: how to pass data between requests in api 
Typescript :: react native vector icon ts file configuaration 
Typescript :: How to exclude a particular test group from a test case execution? 
Typescript :: React Draft Wysiwyg typescript 
Typescript :: Fragment no longer exists 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =