Angular 2路线结束/

时间:2016-09-06 11:59:19

标签: angular angular2-routing

我很想让网址结束" /"

例如:

  • localhost:8080 / contacts /
  • 本地主机:8080 /反馈/

现在我使用这样的网址:

  • 本地主机:8080 /联系人
  • 本地主机:8080 /反馈

我的路线配置

const routes: Routes = [
    {path: '',        component: HomeComponent},
    {path: 'about',        component: AboutComponent},
    {path: 'contacts',        component: ContactsComponent},
    {path: 'feedback',        component: FeedbackComponent},
    //{path: '**',        component: e404Component}
];

我在头标记中使用基本标记

<base href="/"></base>

我尝试配置我的路由器

const routes: Routes = [
    {path: '',        component: HomeComponent},
    {path: 'about/',        component: AboutComponent},
    {path: 'contacts/',        component: ContactsComponent},
    {path: 'feedback/',        component: FeedbackComponent},
    //{path: '**',        component: e404Component}
];

但我收到错误

EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: 'feedback'

1 个答案:

答案 0 :(得分:0)

您肯定可以在路线中拥有/。你的代码似乎是正确的。请检查您已应用路由器链接的HTML模板。

你不应该使用:

[routerLink]="['feedback']" //This does not match with your path feedback/

请改用:

[routerLink]="['feedback/']" //This should definitely work.

如果这不起作用,请上传模板文件以跟踪错误。