gpt4 book ai didi

Angular 2 RC5 子路由问题

转载 作者:太空狗 更新时间:2023-10-29 17:55:09 24 4
gpt4 key购买 nike

我正在尝试让子路由正常工作,这是我遇到的错误:

EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: 'settings'

这是我的 app.modules.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { routeComponents, routing, appRoutingProviders } from './app.routes';


@NgModule({
declarations: [
AppComponent,
routeComponents
],
imports: [
BrowserModule,
CommonModule,
FormsModule,
routing
],
providers: [ appRoutingProviders ],
entryComponents: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {

}

这是我的 app.routes.ts

import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard/';
import { settingsRoutes, settingsComponents } from './settings/';

const appRoutes: Routes = [
{ path: '', redirectTo: 'dashboard', pathMatch: 'full'},
{ path: 'dashboard', component: DashboardComponent },
...settingsRoutes
];

export const appRoutingProviders: any[] = [

];

export const routeComponents: any[] = [
DashboardComponent,
...settingsComponents
];

export const routing = RouterModule.forRoot(appRoutes, {useHash: true});

这是我的 settings.routes.ts

import { Routes } from '@angular/router';
import { SettingsComponent } from "./settings.component";
import { DashboardSettingsComponent } from "./dashboard-settings/dashboard-settings.component";

export const settingsRoutes: Routes = [
{
path: 'settings',
component: SettingsComponent,
children: [
{ path: 'dashboard-settings', component: DashboardSettingsComponent }
]
}
];

export const travelSettingsComponents = [
SettingsComponent,
DashboardSettingsComponent
];

**如果我从 settings.routes.ts 文件中删除这一行,没有错误,它允许我转到设置路由:

{ path: 'dashboard-settings', component: DashboardSettingsComponent }

最佳答案

如果你有一 strip child 的路线,我相信你需要像这样指定一个默认的 child 路径:

children: [
{ path: '', component: SettingsComponent },
{ path: 'dashboard-settings', component: DashboardSettingsComponent }
]

这将产生以下 URL:/settings/settings/dashboard-settings

关于Angular 2 RC5 子路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38926246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com