Javascript 角度布线:如何将所有未知嵌套布线重定向到一个组件?
目前我有以下路由器:Javascript 角度布线:如何将所有未知嵌套布线重定向到一个组件?,javascript,angular,routes,Javascript,Angular,Routes,目前我有以下路由器: const routes: Routes = [ { path: '', redirectTo: 'presentation', pathMatch: 'full' }, { path: 'presentation', component: PresentationPageComponent }, { path: 'news', component: NewsPageComponent }, { path: 'tools', component: Too
const routes: Routes = [
{ path: '', redirectTo: 'presentation', pathMatch: 'full' },
{ path: 'presentation', component: PresentationPageComponent },
{ path: 'news', component: NewsPageComponent }, {
path: 'tools', component: ToolsPageComponent,
children: [
{ path: 'unit-selector', component: UnitSelectorComponent },
{ path: 'object-selector', component: ObjectSelectorComponent },
] },
{ path: 'games', component: GamesPageComponent },
{ path: '**', component: Error404PageComponent }
];
我的问题有两方面:
路由器正确地将所有错误路由(如mydomain.com/badRoute
和mydomain.com/incorrectRoute
)重定向到Error404PageComponent,但一旦路由嵌套,如mydomain.com/badRoute/random
或mydomain.com/badRoute/stuff
,甚至在有效的嵌套路由(如mydomain.com/tools/unit selector
web navigator(尝试了Firefox和Edge)在控制台中显示白色屏幕和错误(由于MIME类型不正确,资源被阻止)
路由mydomain.com/tools
工作正常,并在ToolsPageComponent中显示Error404PageComponent
我如何使我的路线正常工作
注意:我使用WebStorm IDE在本地运行网站(它没有服务器/后端)
下面是错误的图片(这只发生在嵌套路由上):
在
app routing.module.ts
中,似乎有两个{path:'**',component:Error404PageComponent}
。从子路由中删除{path:'**',component:Error404PageComponent}
,只保留路由中的最后一个。会好的
我在这给你装了一个箱子。在我的示例中,第三个选项卡未定义路由
是一个多个未定义路由,如“/home/page1/undefined/nested/route”
,如果单击该选项卡,您将被正确重定向到home
组件。这似乎对我当前的问题没有任何影响(如果信息有帮助,我正在使用WebStorm IDE)。我将编辑我的问题以包含您的答案,因为在StackBlitz上对我的示例进行机械检查似乎是一个好主意。我可以看到它工作,但我不理解为什么我的示例不工作;我不断收到MIME错误,我不明白是什么导致了这些错误。错误是什么?将错误消息添加到您的问题中可以帮助您。当然,我将添加一个scre嗯现在