我通过为路由创建子自定义模块来清理我的根路由文件,这是脚本:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SigninComponent } from './signin/signin.component';
import { SignupComponent } from './signup/signup.component';
const childRoutes: Routes = [
{path: 'signin', component: SigninComponent},
{path: 'signup', component: SignupComponent}
];
@NgModule({
imports: [
RouterModule.forChild(childRoutes)
],
exports:[RouterModule]
})
export class ChildRoutingModule { }
根路由模块现在是:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SigninComponent } from './auth/signin/signin.component';
import { SignupComponent } from './auth/signup/signup.component';
import { NotfoundComponent } from './notfound/notfound.component';
import { ChildRoutingModule } from './auth/auth.route'
const appRoutes: Routes = [
{path: '', redirectTo:'/signup', pathMatch:'full'},
{path: '**', component: NotfoundComponent}
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
],
exports:[RouterModule]
})
export class AppRoutingModule { }
我将2路线模块导入了app.module.ts:
import ...
import ...
import { AppRoutingModule } from './routes'
import { ChildRoutingModule } from './auth/auth.route'
@NgModule({
declarations: [
AppComponent
],
imports: [
AppRoutingModule,
ChildRoutingModule,
BrowserModule,
AuthModule,
RouterModule
],
providers: [AuthService],
bootstrap: [AppComponent]
})
export class AppModule { }
现在的问题出在app的启动组件上,即注册组件,url是正确的:http://localhost:4200/signup
但显示的组件是404组件,它在根路由组件中由{{1}定义}}
要提及控制台上没有错误显示
答案 0 :(得分:2)
您需要最后导入AppRoutingModule
。 dojo page
答案 1 :(得分:1)
将其更改为:
uploadSessionFinishData
你需要最后加载AppRoutingModule,因为在该路由之前路由需要知道所有子路由,以便在初始化时进行深层次的路由。
或者它将重定向到已定义的错误组件。