Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度搜索中Url路径的构造_Angular_Url_Routing - Fatal编程技术网

Angular 角度搜索中Url路径的构造

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

我使用的是Angular 8和Django 3。我不明白我的url路径是如何在Angular中构建的。我有一个
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 to
list
->localhost/main/list->route to
detail
->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>