Ionic 如何为独立页面导航定义Angular嵌套路径

8zzbczxx  于 2023-05-05  发布在  Ionic
关注(0)|答案(1)|浏览(147)

我有一个Ionic-Angular Web应用程序,我试图在上面创建一个类似网站的路由方案,其中包含独立页面的嵌套路由。
到目前为止,我的路由定义如下:

export const routes: Routes = [
  { path: "monitor", loadChildren: () => import('./pages/storyline/story-list/story-list.module').then(m => m.StoryListPageModule) },
  { path: "monitor/story", pathMatch: 'full', loadChildren: () => import('./pages/storyline/story-home/story-home.module').then(m => m.StoryHomePageModule) }
]

@NgModule({
  imports: [
    RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }

下面是我如何从父页面(从路由monitor上的StoryListPage)转到子页面(路由monitor/story上的StoryHomePage

this.router.navigate(["story"], { replaceUrl: true, relativeTo: this.route });

这工作正常,但是当我在monitor/story路由上刷新页面时,它不会加载页面并返回以下错误:

Refused to apply style from 'http://localhost:8100/monitor/styles.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
story:34          GET http://localhost:8100/monitor/runtime.js net::ERR_ABORTED 404 (Not Found)
story:34          GET http://localhost:8100/monitor/polyfills.js net::ERR_ABORTED 404 (Not Found)
story:34          GET http://localhost:8100/monitor/vendor.js net::ERR_ABORTED 404 (Not Found)
story:34          GET http://localhost:8100/monitor/main.js net::ERR_ABORTED 404 (Not Found)
story:34          GET http://localhost:8100/monitor/styles.js net::ERR_ABORTED 404 (Not Found)
story:1 Refused to execute script from 'http://localhost:8100/monitor/styles.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
story:34          GET http://localhost:8100/monitor/scripts.js net::ERR_ABORTED 404 (Not Found)
story:1 Refused to execute script from 'http://localhost:8100/monitor/scripts.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
favicon.png:1          GET http://localhost:8100/monitor/assets/icon/favicon.png 404 (Not Found)

到目前为止,我发现的所有内容都是关于嵌套路由的,在每个父页面中都有router-outlet,并定义了子路由,这可能不是我所需要的。我只是在寻找基本的页面导航之间的路线,有嵌套式的格式,如一个网站,但实际上没有嵌套页面在另一个。
如果我能解决这个错误,问题中描述的解决方案似乎非常接近我所需要的。

f45qwnt8

f45qwnt81#

快跑

ionic generate page your-page-name

在要创建嵌套路由的页面文件夹目录中。

相关问题