我有一个带有多个出口路线的Angular 7应用程序。我的路线变量如下。
const routes: Routes = [
{
path: "spa/:id",
component: TopforecastComponent,
outlet: 'topforecast',
},
{
path: '',
component: FrettirComponent
},
{
path: '',
component: SidebarComponent,
outlet: 'sidebar'
},
{
path: 'spa/:id',
component: FrettirComponent
},
{
path: 'spa/:id',
component: SidebarComponent,
outlet: 'sidebar'
},
{
path: '',
component: TopforecastComponent,
outlet: 'topforecast'
},
{
path: "spa/:id/:ar/:man/:dagur",
component: DagsspaComponent
},
{
path: 'frett/:id',
component: FrettComponent
}
];
当我尝试在topforecast组件(topforecast出口)中检索参数时,我不确定。
ngOnInit() {
this.route.params.subscribe(params => {
console.log(params)
});
}
这是组件代码:
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {ActivatedRoute} from '@angular/router';
@Component({
selector: 'app-topforecast',
templateUrl: './topforecast.component.html',
styleUrls: ['./topforecast.component.css']
})
export class TopforecastComponent implements OnInit {
users$: Object;
constructor(private http: HttpClient, private route: ActivatedRoute) { }
如何从出口路径访问url参数。