Angular 2在重新加载时重用相同的路由

时间:2017-06-17 15:11:49

标签: angular angular-router

如果我重新加载页面(F5)或将其打开到新标签页面,我想使用相同的路线。

例如,我使用以下路线:

http://localhost:4200/show-category/-KmhdoAJO0WQbTzS9gll

如果我按F5,结果是:

http://localhost:4200/

问题是它显示了与以前相同的组件,但由于缺少id,因此没有值。该应用程序崩溃。

(我在另一个问题上坐了几个小时,也许我现在没有集中精力去发现错误。)

我希望有一个人可以很快帮助我。

const appRoutes: Routes =  [
  { path: '', component: HomeComponent },
  { path: 'access-denied', component: AccessDeniedComponent },
  { path: 'add-category', component: AddCategoryComponent },
  { path: 'add-reply/:id', component: AddReplyComponent },
  { path: 'add-topic/:id', component: AddTopicComponent },
  { path: 'change-user-roles', component: ChangeUserRolesComponent },
  { path: 'edit-category/:id', component: EditCategoryComponent },
  { path: 'edit-reply/:id', component: EditReplyComponent },
  { path: 'edit-topic/:id', component: EditTopicComponent },
  { path: 'delete-category/:id', component: DeleteCategoryComponent },
  { path: 'delete-reply/:id', component: DeleteReplyComponent },
  { path: 'delete-topic/:id', component: DeleteTopicComponent },
  { path: 'register-user', component: RegisterUserComponent },
  { path: 'show-category/:id', component: ShowCategoryComponent },
  { path: 'show-topic/:id', component: ShowTopicComponent },
  { path: 'user-profile', component: UserProfileComponent },
]

0 个答案:

没有答案