我正在尝试为我的应用程序的某些URL添加查询参数。我正在使用快照方法,并且具有将查询参数添加到URL的功能。一切正常,除非我尝试将查询参数添加到我的家庭URL中,然后我的URL被
{ path: '**', redirectTo: 'not-found'}
,并将其重定向到NotFoundComponent。
我的HomeComponent的路径定义如下:
{ path: ':language', component: HomeComponent}
函数定义如下:
this.router.navigate(['en'], {
queryParams: {'param1': this.value1, 'param2': this.value2}
});
并且我知道该函数有效,因为当我尝试为这样的其他组件添加查询参数时:
this.router.navigate(['en/other-component'], {
queryParams: {'param1': this.value1, 'param2': this.value2}
});
没有问题,我被重定向到想要的页面,查询参数被传递到URL。
答案 0 :(得分:0)
如果第一段不是以/开头,则为相对路径。 router.navigate需要一个relativeTo参数进行相对导航
$(document).ready(function(){
$("#search").on("keyup", function()
{
var value = $(this).val().toLowerCase();
$(".child").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
//here is the code to hide
$(".parent").each(function() {
if($(this).find('.child:visible').length===0)
$(this).hide();
else
$(this).show();
});
});
});
示例:
this.router.navigate(['en'], {
queryParams: {'param1': this.value1, 'param2': this.value2},relativeTo: this.route
});