我试图通过单击图标导航到新页面,下面是代码
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' },
}
您可以使用“router.navigate”代替“router.navigateByUrl”:
this.router.navigate([URL], {queryParams: {id: this.prj}});
简单地使用字符串插值
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);
this.router.navigate(['/route1'], { variable1: "Value" });
this.router.navigateByUrl('/route1', { variable1: "Value" });
请不要:如果您的网址是
urlencoded
,请使用navigateByUrl
,如果您的网址不是urlencoded
,请使用navigate