[英]Subject is not working when route navigating from one component to another component in Angular 6
[英]How to decode the URL when navigating one route to another roue in angular 5?
我想使用查詢參數從一個路由導航到另一個路由頁面。
var name = "engine & machinery";
this.router.navigateByUrl('dashboard?isopen='+true+'&name='+name);
由此,導航到儀表板頁面,但查詢參數不正確。
網址來了,
http://localhost:4200/dashboard?isopen=true&name=engine%20&%20machinery=
通過以下代碼獲取查詢參數,
console.log("testt", this.route.snapshot.queryParamMap.get('name'));
它只返回"engine"
。
因此,有人可以幫助我解碼url以及如何獲取參數值嗎?
提前致謝
使用encodeURIComponent
使用此類特殊字符對URL進行編碼。
var name = encodeURIComponent("engine & machinery");
在創建URL時。
然后在接收端,使用decodeURIComponent
對其進行解碼
像這樣:
const encodedName = this.route.snapshot.queryParamMap.get('name')
const decodedName = decodeURIComponent(encodedName);
// This would yield `engine & machinery`
這是供您參考的示例StackBlitz 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.