我无法使用 example.com/movie 直接访问该路线。我在页面上收到错误消息 Cannot GET /movie .
当我从特定路线刷新页面时,我收到相同的错误无法获取/xyz-route
我的app.routing.module是
const routes: Routes = [
{path: 'movie',
component: movieComponent },
{path: 'home',
component: homeComponent },
{ path: '', redirectTo: '/movie', pathMatch: 'full'}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
我该如何解决这个问题?
在路由配置中,使用组件类而不是字符串文字:
const routes: Routes = [
{ path: 'movie', component: MovieComponent },
{ path: 'home', component: HomeComponent },
{ path: '', redirectTo: '/movie', pathMatch: 'full' }
];