角度路由-如何为xxx / xxx之类的嵌套路由正确使用通配符路由?

时间:2020-08-27 10:43:36

标签: angular angular-ui-router angular-routing

对于xxx / xxx之类的嵌套路由,如何正确使用通配符路由?

我想将host:port / XXX / XXX重定向到页面未找到,但是,我的通配路由仅接受路由host:port / XXX,而不接受host:port / XXX / XXX。

这是我在app.module.ts上配置的路由:

  const routes: Routes = [     
  {
    path: 'main',
    component: MainComponent
  },
  {
    path: '',
    component: PageNotFoundComponent
  },
  {
    path: '**',
    redirectTo: ''
  }
];

RouterModule.forRoot(routes)

  • 对于网址“ host:port / main”,我将获得主页。
  • 对于网址“ host:port / XXXX”,我将获得未找到页面。
  • 但是,对于URL'host:port / XXXX / XXXX',我会得到一个空白页面。
    • 它只能成功下载index.html(并以“ XXXX”命名),没有style.css,没有资产,没有main.js。
    • 使用ng服务和将其作为生产版本都存在相同的问题。

我的文件:(使用Angular 10.0.10)

app
--- page-not-found/page-not-found.component.ts
--- main/maincomponent.ts
--- app.component.ts
--- app.module.ts
assets
environment
index.html
main.ts
style.css
… (other files auto generated by angular cli)

谢谢。

0 个答案:

没有答案