Angular 角度搜索中Url路径的构造
我使用的是Angular 8和Django 3。我不明白我的url路径是如何在Angular中构建的。我有一个Angular 角度搜索中Url路径的构造,angular,url,routing,Angular,Url,Routing,我使用的是Angular 8和Django 3。我不明白我的url路径是如何在Angular中构建的。我有一个restaurantlist组件和一个restaurantdetail组件,在我的应用程序路由模块中有以下路径。ts: const routes: Routes = [ {path:'restaurantlist', component:RestaurantlistComponent}, {path:'restaurantdetail/:id', component:Restau
restaurantlist
组件和一个restaurantdetail
组件,在我的应用程序路由模块中有以下路径。ts
:
const routes: Routes = [
{path:'restaurantlist', component:RestaurantlistComponent},
{path:'restaurantdetail/:id', component:RestaurantViewComponent}
];
在我的restaurantlist.component.html
文件中:
<h2>List of Restaurants</h2>
<ul *ngFor = "let restaurant of restaurants">
<a [routerLink]="['restaurantdetail', restaurant.id]">{{restaurant.name}}</a>
</ul>
欢迎您的任何意见 尝试在路由之前添加“/”
{{restaurant.name}
一条没有的路线,/
是一条相对路线,意味着你“深入”一条路线
localhost/main->route tolist
->localhost/main/list->route todetail
->localhost/main/list/detail
带有/
的路线是一条绝对路线,意味着您希望准确到达那里
localhost/main->路由到/list
->localhost/list->路由到/detail
->localhost/detail
如果你在列表页面,你可以转到
detail
,但是如果你在主页上想转到detail,你必须使用/main/list/detail
或list/detail
尝试/restaurantDetail来使用绝对路径w,花了很多时间来追踪,真的很感激这项工作
<a [routerLink]="'/restaurantlist'">See Available Restaurants</a>