我有一个页面,该页面可以被另一个带有参数化URL的应用程序打开。
例如:sitename.com/language/myapplication?param1=xxx¶m2=xxx
在我的组件.ts中,我有:
this.param1= this.route.snapshot.queryParamMap.get('param1');
this.param1= this.route.snapshot.queryParamMap.get('param2');
this.router.navigate(['/myapplication'],
{
queryParams: {
param1: this.param1, param2: this.param1
}
});
我也在使用路由模块:
const routes: Routes = [
{ path: '', redirectTo: '/myapplication', pathMatch: 'full' },
{ path: 'myapplication', component: myComponent },
{ path: '**', component: PageNotFoundComponent }
];
当我直接使用参数打开URL时,它可以正常工作。
问题1:
我上有多种语言,i18n,所以当我通过下拉菜单更改语言时,参数消失,并且重定向到mysite.com/language/myapplication
,但我需要类似sitename.com/fr/myapplication?param1=xxx¶m2=xxx
的东西>
问题2:
我希望在所有情况下都强制“找不到页面”,除非我具有带有参数的URL
问题3:
如何将这些参数从可选参数转换为必需参数?
我有一个页面,该页面将被另一个带有参数化URL的应用程序打开。例如:sitename.com/language/myapplication?param1=xxx¶m2=xxx在我的组件.ts中,我具有:this.param1 = this.route ....
问题1:这不是角路由器的工作。您需要使用正确的URL来重新加载浏览器的语言,请勿为此使用路由器,例如:location.assign(location.href.replace('/fr', '/en-US'))
;
使用路由参数代替查询字符串。