Polymer 聚合应用程序路由查询字符串格式
我用Polymer 聚合应用程序路由查询字符串格式,polymer,polymer-1.0,Polymer,Polymer 1.0,我用app-location和app-route替换了应用程序中的PageJS路由,除了查询参数外,其他一切似乎都正常工作。我注意到它只能读取像host?param1=val1 35;/view,而不能像PageJS过去那样读取host#view?param1=val1 经过进一步的挖掘,我发现这实际上是一个。我发现PageJS和Angular可以使用非标准的查询字符串格式很奇怪 是否有方法使用app route的query params属性读取非标准查询参数以实现向后兼容性 非标准表单在Pag
app-location
和app-route
替换了应用程序中的PageJS路由,除了查询参数外,其他一切似乎都正常工作。我注意到它只能读取像host?param1=val1 35;/view
,而不能像PageJS过去那样读取host#view?param1=val1
经过进一步的挖掘,我发现这实际上是一个。我发现PageJS和Angular可以使用非标准的查询字符串格式很奇怪
是否有方法使用
app route
的query params
属性读取非标准查询参数以实现向后兼容性 非标准表单在PageJS中工作,因为PageJS通过然后手动解析URL中的查询字符串。我可能会做类似的事情。另一方面,来获取查询参数
如果需要坚持使用
,可以通过monkey patching添加向后兼容的支持,monkey patching负责解析
的URL
猴子补丁
:
Polymer({
is: 'my-app',
ready: function() {
this._setupAppLocation();
},
_setupAppLocation: function() {
// assumes <app-location id="location">
const ironLocation = this.$.location.$$('iron-location');
if (!ironLocation) return;
ironLocation._urlChanged = function() {
this._dontUpdateUrl = true;
this.path = window.decodeURIComponent(window.location.pathname);
if (window.location.hash.includes('?')) {
const parts = window.location.hash.split('?');
this.hash = window.decodeURIComponent(parts[0].slice(1));
this.query = parts[1];
// Prepend other query parameters found in standard location
if (window.location.search) {
this.query = window.location.search.substring(1) + '&' + this.query;
}
} else {
this.query = window.location.search.substring(1);
}
this._dontUpdateUrl = false;
this._updateUrl();
};
}
});
<nebula-location data="{{locationData}}"></nebula-location>
<div>foo=[[locationData.queryParams.foo]]</div>
<a href="[[rootPath]]#view?foo=123">#view?foo=123</a>
<a href="[[rootPath]]?foo=123#view">?foo=123#view</a>