Angular 2 - 在url中使用hashtag发送值

时间:2021-03-06 10:25:18

In my application I have a list of registered products.

在我的申请中,我有一份注册产品清单。

I am trying to send the product name in the url.

我正在尝试在网址中发送产品名称。

However the product name it has # hashtag and the product name is arriving incomplete on the server:

但是它的产品名称#hashtag和产品名称在服务器上到达不完整:

front end

var product = "PLASTIC #1JQ-M 1CV T-PLAS"
return this._http.get(Config.URL_SITE + 'list/productLen?product='+product)...

back end

router.get('/productLen', function(req, res, next) {
  var productName= req.query.product;
  console.log(productName) //PLASTIC
...

How to make the productName variable receive the full name? "PLASTIC #1JQ-M 1CV T-PLAS"

如何使productName变量获得全名? “PLASTIC#1JQ-M 1CV T-PLAS”

1 个解决方案

#1


2  

You should use encodeURIComponent() function before adding product name to URL.

在将产品名称添加到URL之前,应使用encodeURIComponent()函数。

var product = "PLASTIC #1JQ-M 1CV T-PLAS"
return this._http.get(Config.URL_SITE + 'list/productLen?product=' + encodeURIComponent(product))...

Everything after hash is stripped off by the browser Why the hash part of the URL is not in the server side?.

散列后的所有内容都被浏览器剥离为什么URL的散列部分不在服务器端?

There are alternative solutions: How to get Url Hash (#) from server side, but they are mostly how to retrieve hash on server in general.

还有其他解决方案:如何从服务器端获取Url Hash(#),但它们主要是如何在服务器上检索哈希值。

#1


2  

You should use encodeURIComponent() function before adding product name to URL.

在将产品名称添加到URL之前,应使用encodeURIComponent()函数。

var product = "PLASTIC #1JQ-M 1CV T-PLAS"
return this._http.get(Config.URL_SITE + 'list/productLen?product=' + encodeURIComponent(product))...

Everything after hash is stripped off by the browser Why the hash part of the URL is not in the server side?.

散列后的所有内容都被浏览器剥离为什么URL的散列部分不在服务器端?

There are alternative solutions: How to get Url Hash (#) from server side, but they are mostly how to retrieve hash on server in general.

还有其他解决方案:如何从服务器端获取Url Hash(#),但它们主要是如何在服务器上检索哈希值。