使用 navigateByUrl() 传递查询参数
Passing query parameter by using navigateByUrl()
我正在尝试通过单击图标导航到新页面,下面是代码
this.prj = e.data.project_number;
this.router.navigateByUrl('/dashboard/ProjectShipment/634');
而不是这个硬编码的查询参数 000634
我必须将 this.prj
传递给它。我的路径如下
const appRoutes: Routes = [
{
path: 'dB',
data: { title: 'Dashboard' },
children: [
{
path: 'ProjectShipment/:reportProject',
component: ProjectShipmentComponent,
data: { title: 'Project Shipment' },
}
// 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);
编辑:这也值得一看
您可以使用 'router.navigate' 代替 'router.navigateByUrl':
this.router.navigate([URL],{ queryParams: { id: this.prj });
简单地使用字符串插值
this.router.navigateByUrl(`/dashboard/ProjectShipment/${this.prj}`);
this.router.navigate(['/route1'], { variable1: "Value" });
this.router.navigateByUrl('/route1', { variable1: "Value" });
请none:如果你的url是urlencoded
使用navigateByUrl
,如果你的url不是urlencoded
使用navigate
我正在尝试通过单击图标导航到新页面,下面是代码
this.prj = e.data.project_number;
this.router.navigateByUrl('/dashboard/ProjectShipment/634');
而不是这个硬编码的查询参数 000634
我必须将 this.prj
传递给它。我的路径如下
const appRoutes: Routes = [
{
path: 'dB',
data: { title: 'Dashboard' },
children: [
{
path: 'ProjectShipment/:reportProject',
component: ProjectShipmentComponent,
data: { title: 'Project Shipment' },
}
// 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);
编辑:
您可以使用 'router.navigate' 代替 'router.navigateByUrl':
this.router.navigate([URL],{ queryParams: { id: this.prj });
简单地使用字符串插值
this.router.navigateByUrl(`/dashboard/ProjectShipment/${this.prj}`);
this.router.navigate(['/route1'], { variable1: "Value" });
this.router.navigateByUrl('/route1', { variable1: "Value" });
请none:如果你的url是urlencoded
使用navigateByUrl
,如果你的url不是urlencoded
使用navigate