使用"?"进行角度路由在哈希

时间:2017-11-10 17:01:35

标签: angular angular4-router

我们需要在url中插入带有问号的哈希值。就像

本地主机:4200 / 码为HASHCODE

并且只读哈希。

现在正在阅读它而没有问号,但是当我们把它放在哈希之前时,它就不起作用了。

我们如何正确配置de routing以达到此要求?

提前致谢,

1 个答案:

答案 0 :(得分:1)

你想要完成的是不可能和不正确的。查询参数是首先使用URL传输数据的标准的一部分,这些参数是键值。在Angular中,您可以执行以下操作:

{path: ':hashcode', component: MyComponent} // your route
// in MyComponent
constructor(private route: ActivatedRoute){}
ngOnInit() {this.route.params.subscribe(params => // do something with params)}

或者这样:

{path: '', component: MyComponent // you don't need to define query parameters inside the route definition}
// same code inside the component, but just subscribe to queryParams Observable instead of params 

这种“业务要求”是奇怪的,不必要的和无用的。你需要面对它。

相关问题