Angular 2+路由重定向

Angular 2+ Routing redirect

这似乎是一个愚蠢的问题,但我无法理解这个路由

routes.ts:

const APP_ROUTES: Routes = [
  { path: 'home', component: HomeComponent },
  { path: 'articles', component: ArticulosComponent },
  { path: 'article/:id', component: ArticuloComponent },
  { path: '', pathMatch: 'full', redirectTo: 'home' },
  { path: '**', pathMatch: 'full', redirectTo: 'notfound' }
];

当访问 localhost:4200/article/6 时,路由器重定向到 localhost:4200/#/home 但当手动写入 localhost:4200/#/article/6 时工作正常。

首先,注意#符号,为什么会有它,它有什么不同?并且...我指定 'manually' 因为即使通过代码将 # 符号添加到路径(例如 <a href="#/article/6"></a>)也会继续重定向到 home

主要question/problem是"Which would be the correct link or rule in other to load the correct component?"

您可以从 app.module.ts

中 useHash 的路由更改值中删除 #
RouterModule.forRoot(ROUTES, { useHash: false }),

您可以添加 pathMatch: 'full' 家庭和文章路线