Angular 4:更改url,但组件未呈现
Angular 4: changing url, but component is not rendered
我正在尝试使用 routerLink = "selected"
从一个组件 link 一个组件
const routes: Routes = [
{
path: '',
children: [
{
path: 'account',
component: AccountComponent,
children: [
{
path: 'selected',
component: SelectedComponent,
},
],
},
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class AccountSettingsRoutingModule { }
这是帐户组件
import { Component, OnInit, AfterViewInit } from '@angular/core';
import { Router, ActivatedRoute, RouterModule } from '@angular/router';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Http, Response, Headers } from '@angular/http';
@Component({
selector: 'app-list-accounts',
templateUrl: './accounts-list.component.html',
styleUrls: ['./accounts-list.component.scss']
})
export class AccountComponent implements OnInit {
constructor(private http: HttpClient, private router: Router) { }
ngOnInit() {}
}
url 正在更改为所需的 dashboard/account/selected,但未加载视图。
将 <router-outlet></router-outlet>
添加到 AccountComponent。在 docs.
中阅读更多内容
我正在尝试使用 routerLink = "selected"
const routes: Routes = [
{
path: '',
children: [
{
path: 'account',
component: AccountComponent,
children: [
{
path: 'selected',
component: SelectedComponent,
},
],
},
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class AccountSettingsRoutingModule { }
这是帐户组件
import { Component, OnInit, AfterViewInit } from '@angular/core';
import { Router, ActivatedRoute, RouterModule } from '@angular/router';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Http, Response, Headers } from '@angular/http';
@Component({
selector: 'app-list-accounts',
templateUrl: './accounts-list.component.html',
styleUrls: ['./accounts-list.component.scss']
})
export class AccountComponent implements OnInit {
constructor(private http: HttpClient, private router: Router) { }
ngOnInit() {}
}
url 正在更改为所需的 dashboard/account/selected,但未加载视图。
将 <router-outlet></router-outlet>
添加到 AccountComponent。在 docs.