[英]Passing query parameter by using navigateByUrl()
I am trying to Navigate to a new page on click of an icon and below is the code我正在尝试通过单击图标导航到新页面,下面是代码
this.prj = e.data.project_number;
this.router.navigateByUrl('/dashboard/ProjectShipment/634');
Instead of this hardcoded query parameter 000634
I have to pass a this.prj
in to it.我必须将this.prj
传递给它,而不是这个硬编码的查询参数000634
。 My path is like below我的路径如下
const appRoutes: Routes = [
{
path: 'dB',
data: { title: 'Dashboard' },
children: [
{
path: 'ProjectShipment/:reportProject',
component: ProjectShipmentComponent,
data: { title: 'Project Shipment' },
}
You can use 'router.navigate' instead 'router.navigateByUrl':您可以使用“router.navigate”代替“router.navigateByUrl”:
this.router.navigate([URL],{ queryParams: { id: this.prj });
Simply use string interpolation简单地使用字符串插值
this.router.navigateByUrl(`/dashboard/ProjectShipment/${this.prj}`);
// Set our navigation extras object
// that passes on our global query params and fragment
let navigationExtras: NavigationExtras = {
queryParams: {...},
state: {...}
};
// Redirect the user
this.router.navigateByUrl(redirect, navigationExtras);
NavigationExtras docs NavigationExtras 文档
EDIT: https://stackoverflow.com/a/44865817/5011818 this is also worth to look at编辑: https ://stackoverflow.com/a/44865817/5011818 这也值得一看
I am trying to Navigate to a new page on click of an icon and below is the code我试图通过点击一个图标导航到一个新页面,下面是代码
this.prj = e.data.project_number;
this.router.navigateByUrl('/dashboard/ProjectShipment/634');
Instead of this hardcoded query parameter 000634
I have to pass a this.prj
in to it.我必须将this.prj
传递给它,而不是这个硬编码的查询参数000634
。 My path is like below我的路径如下
const appRoutes: Routes = [
{
path: 'dB',
data: { title: 'Dashboard' },
children: [
{
path: 'ProjectShipment/:reportProject',
component: ProjectShipmentComponent,
data: { title: 'Project Shipment' },
}
this.router.navigate(['/route1'], { variable1: "Value" });
this.router.navigateByUrl('/route1', { variable1: "Value" });
Please none: if your url is urlencoded
use navigateByUrl
, if your url is not urlencoded
use navigate
请不要:如果你的 url 是urlencoded
使用navigateByUrl
,如果你的 url 不是urlencoded
使用navigate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.