简体   繁体   English

哈希之前用“?”进行角路由

[英]Angular Routing with “?” before hash

We need to insert a hash in the url with a question mark before. 我们需要在网址前插入带有问号的哈希。 Just like 就像

localhost:4200/? 本地主机:4200 /? HASHCODE 码为HASHCODE

and read only the hash. 并仅读取哈希。

Right now is reading it without the question mark, but when we put it before the hash, it doest not work. 目前正在读取它而没有问号,但是当我们将其放在散列之前时,它将无法正常工作。

How can we configure de routing properly to reach this requirement? 我们如何正确配置路由选择以满足此要求?

Thanks in advance, 提前致谢,

What you try to accomplish is impossible and incorrect. 您试图实现的目标是不可能且不正确的。 Query Parameters are a part of standard of using URL for transferring data, in the first place, and those parameters are key-value . 首先,查询参数是使用URL传输数据的标准标准的一部分,这些参数是键值 In Angular you can do the following: 在Angular中,您可以执行以下操作:

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

Or this way: 或者这样:

{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 

This "business requirement" is weird, unnecessary and useless. 这种“业务需求”是怪异的,不必要的和无用的。 You need to confront it. 您需要面对它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM