大家好,如果您有空闲时间,请帮助我解决我的问题。我似乎找不到可能的解决方案。因此,我尝试更改我的route
,到目前为止,我没有发现任何问题,但是如果您发现任何缺陷,请告诉我,并且到目前为止,我也尝试查找任何类型错误并仔细检查我的组件我找不到一个,但随后又让我知道。我尝试输入路线URL,但它可以正常显示,但不会显示相同的页面,也不会将我重定向到所需的页面。我什至删除并安装了node module
,但不幸的是问题仍然存在。老实说,我只想尝试在Angular 6中是否仍然可以使用child route
。但是无论如何,我将为您提供route模块,html组件和其他组件。
首先是我的路线模块:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ContactComponent } from './contact/contact.component';
import { ComponentDetailComponent } from './contact/component-detail/component-detail.component';
import { ContactDescriptionComponent } from './contact/component-detail/contact-description/contact-description.component';
const routes: Routes = [
{
path: 'contact',
component: ContactComponent,
children: [
{
path: ':id',
component: ComponentDetailComponent,
children: [
{
path: 'details/:name',
component: ContactDescriptionComponent
}
]
}
]
},
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule { }
我的app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ContactComponent } from './contact/contact.component';
import { ComponentDetailComponent } from './contact/component-detail/component-detail.component';
import { ContactDescriptionComponent } from './contact/component-detail/contact-description/contact-description.component';
@NgModule({
declarations: [
AppComponent,
ContactComponent,
ComponentDetailComponent,
ContactDescriptionComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我的app.component.html:
<app-contact></app-contact>
<router-outlet></router-outlet>
我的contact.component.html:
<h1>Contact works!</h1>
<a [routerLink]="['id']">Contact Details</a>
我的component-detail.component.html:
<h3>Component-detail Works!</h3>
<a [routerLink]="['details','name']" >Description</a>
最后是我的contact-description.component.html:
<h3>Contact-description Works!</h3>
如果您有什么要我加起来的,请告诉我。谢谢您,祝您好运