从除空白之外的任何路径刷新时,Angular 应用程序都会出错

问题描述 投票:0回答:1

我无法使用 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 { }

我该如何解决这个问题?

angular angularjs angular-routing
1个回答
0
投票

在路由配置中,使用组件类而不是字符串文字:

const routes: Routes = [
  { path: 'movie', component: MovieComponent },
  { path: 'home', component: HomeComponent },
  { path: '', redirectTo: '/movie', pathMatch: 'full' }
];
© www.soinside.com 2019 - 2024. All rights reserved.