简体   繁体   English

在角度5中将一条路线导航到另一条路线时,如何解码URL?

[英]How to decode the URL when navigating one route to another roue in angular 5?

I want to navigate a page from one route another route with query parameters. 我想使用查询参数从一个路由导航到另一个路由页面。

var name = "engine & machinery";

this.router.navigateByUrl('dashboard?isopen='+true+'&name='+name);

From this, route navigate to dashboard page but query parameters not coming properly. 由此,导航到仪表板页面,但查询参数不正确。

Url comes like, 网址来了,

http://localhost:4200/dashboard?isopen=true&name=engine%20&%20machinery=

Getting query parameters by the following code, 通过以下代码获取查询参数,

console.log("testt", this.route.snapshot.queryParamMap.get('name'));

its return only the "engine" . 它只返回"engine"

So, anyone help me for decoding the url and how to get the parameter value? 因此,有人可以帮助我解码url以及如何获取参数值吗?

Thanks in advance 提前致谢

Use encodeURIComponent to encode the URL with special characters like these. 使用encodeURIComponent使用此类特殊字符对URL进行编码。

var name = encodeURIComponent("engine & machinery");

while creating the URL. 在创建URL时。

And in the receiving end, decode it using the decodeURIComponent 然后在接收端,使用decodeURIComponent对其进行解码

Something like this: 像这样:

const encodedName = this.route.snapshot.queryParamMap.get('name')
const decodedName = decodeURIComponent(encodedName);
// This would yield `engine & machinery`

Here's a Sample StackBlitz for your ref. 这是供您参考的示例StackBlitz

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

相关问题 在Angular 6中从一个组件导航到另一个组件时,主题无法正常工作 - Subject is not working when route navigating from one component to another component in Angular 6 角度2:可观察对象在导航到另一条路线时会自行毁灭 - Angular 2: Observables destroy itself when navigating to another route 在 Angular 中导航时如何处理 URL 中的括号 - How to handle parentheses in URL when navigating in Angular 角度-显示除网址以外的其他路线 - Angular - Display another route than the url one 如何在角度2中将一条路线导航到另一条路线 - how to navigate one route to another in angular 2 使用Angular 6导航到另一个组件时如何确保客户端安全 - how to keep the client safe when navigating to another component using Angular 6 angular-在导航到另一条路线之前将queryParams传递到活动路线 - angular - passing queryParams to active route before navigating to another route Angular 路由器没有导航到路由 - Angular router not navigating to the route 导航到使用相同组件的另一条路线时,组件的角度检索状态 - Angular Retrieve state of a component when navigating to another route that uses the same component Angular2路由器:无需导航即可获取URL路由 - Angular2 Router: Get Route for URL without navigating
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM