Reputation: 47
can you tell me if these considerations are completely correct?
I have this routes: {path:'home:id', Component:'HomeComponent}, {path:'about', Component:'AboutComponent},
I can navigate to the routes path using these two methods:
1)first method: html template(routerLink directive)
<a [routerLink]= "['/home',2]"></a>
When user click a tag, this final URL is generated: domain_name/home/2. The number 2 is the value parameter that replaces the id paramter (path:'home:id'......}. Furthermore, when the user click a tag, the first route will be navigated {path:'home:id', Component:'HomeComponent} and HomeCompnent will be actived and displayed.
2)second method:
Navigating programmatically:
route to navigate to: {path:'about', Component:'AboutComponent}
router.navigate(['/about'])
In this second case, when this statement will be executed, this final URL is generated: domain_name/about, second route will be navigated {path:'about', Component:'AboutComponent} and AboutCompnent will be actived and displayed.
In this examples, in routerLink directive and navigate method, I have passed an absolute path in the array argument, because it starts with a slash. For absolute paths, the router starts matching from the root path at the beginning of the route configuration.
Is everything correct for you or are there errors? It's important
Thanks
Upvotes: 0
Views: 312
Reputation: 535
this 2 method i am generally used check it
1)firstmethod
{path: "",component: HomeComponent},
{path:':id', Component:'HomeComponent},
{path:'about', Component:'AboutComponent} and called in html
<a [routerLink]="Home/id"></a>
<a [routerLink]="about"></a>
2)secondmethod
route same as first method
router.navigate(['/about']);
Upvotes: 0