Angular路由器不能加载带有PathParam的我的页面。
创始人
2024-10-28 03:00:14
0

可能是因为在路由器配置中没有正确地定义PathParam的名称。在定义路由时,确保在路由路径中使用冒号(:)来指定PathParam的名称,并在组件中的路由快照中使用ActivatedRoute服务来检索访问路径中的参数。

以下是示例代码:

定义路由:

{ path: 'my-page/:id', component: MyPageComponent }

在组件中检索PathParam:

import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router';

@Component({ selector: 'app-my-page', templateUrl: './my-page.component.html', styleUrls: ['./my-page.component.css'] }) export class MyPageComponent implements OnInit { id: string;

constructor(private route: ActivatedRoute) { }

ngOnInit() { this.id = this.route.snapshot.paramMap.get('id'); }

}

在上面的代码示例中,我们定义了一个名为“id”的PathParam,并通过在路径中指定参数名称来告诉Angular路由器使用哪个PathParam。在组件中,我们使用ActivatedRoute服务来检索PathParam,然后将其存储在组件变量中以供使用。

相关内容

热门资讯

最终"wepoker... 最终"wepoker怎么开辅助"pokemmo内置修改器(竟然是有辅助软件)-哔哩哔哩1、进入游戏-...
透视辅助"wepok... 透视辅助"wepoker软件安装包"wepoker免费脚本咨询(本来存在有辅助辅助器)-哔哩哔哩一、...
据公告内容"wepo... 据公告内容"wepoker的辅助器"epoker透视(原来是有辅助神器)-哔哩哔哩1、进入游戏-大厅...
透视有挂"wepok... 透视有挂"wepoker免费钻石"wpk辅助器是真的吗(都是真的是有辅助软件)-哔哩哔哩1、下载好w...
这一问题亟待解决"约... 这一问题亟待解决"约局吧德州有挂吗"佛手在线大菠萝辅助(竟然有辅助插件)-哔哩哔哩1、下载好佛手在线...
据了解"wepoke... 据了解"wepoker有人用过吗"红龙poker辅助(果然存在有辅助神器)-哔哩哔哩1、操作简单,无...
近日"wepoker... 近日"wepoker透视脚本是什么"werplan脚本(都是真的是有辅助工具)-哔哩哔哩;1、该软件...
透视脚本"德州hhp... 透视脚本"德州hhpoker是真的吗"红龙poker辅助工具(确实存在有辅助app)-哔哩哔哩1、金...
最终"uupoker... 最终"uupoker有透视吗"xpoker辅助控制(原来是有辅助下载)-哔哩哔哩uupoker有透视...
随着"wepoker... 随着"wepoker有透视吗"wepoker辅助器有哪些功能(真是是有辅助app)-哔哩哔哩1、we...