0
votes

I have some considerations related to angular routing and I would like to know if they are all correct.

Suppose I have a route ({path:'/home', component:HomeComponent}).

To navigate to this path(/home), I can use 3 methods, for example:

1) To Enter the URL in the browser bar

2) To Insert the routerlink directive in the parent component template(in this case AppComponent)

3) To use the navigate method in the parent component class(in this case app.component.ts), this.router.navigate(['/home']).

routerLink and navigate method do the same things, they navigate to a /home route (the browser url is updated) and the component that manages this route(HomeComponent) will be displayed.

Both routerLink and navigate take as argument the same array(the same path of the route), that coincides with the path field value in the route definition {path:'/home', component:HomeComponent}.

Generally, routerLink and router-outlet must always be inserted in the parent route template, i.e. in the parent component tamplate.

everything correct or are there conceptual errors in what I wrote?

Thanks

2

2 Answers

0
votes

There is one conceptual error I found in your understanding of working of the router.

The navigate method by default navigates to absolute path, starting from route (you can provide optional relativeTo option, though). The routerLink directive navigates to relative path (relatively to the component in which it is placed).

Other than that, your understandings about the router seem correct to me.

0
votes

For me apart from navigateByUrl('/home') which you forget to enum, about the concept of navigation in angular all that you said is the same as i know...