尝试使用 reactJS 将查询字符串参数发送到另一个页面
trying to send querystring parameters to another page using reactJS
我正在尝试使用按钮单击事件中的历史对象将查询字符串参数发送到另一个页面,如下所示
const viewChange = (record) => {
debugger;
history.push('/Viewchange?id=record.id&dataid=record.dataid');
};
这是我在 routes.js 文件
中定义的路线
{
path: '/Viewchange/:id/:dataid',
exact: true,
title: 'Viewchange',
icon: 'dashboard',
breadcrumbs: ['dashboard'],
contentComponent: ViewChangeRequest,
isEnabled: () => false,
},
一些我如何得到一个空白页面 url 下面
http://localhost:3000/Viewchange?id=record.id&dataid=record.dataid#
我不确定在这种情况下我哪里做错了,谁能告诉我如何将查询字符串值附加到 url
下面的代码是我要重定向的组件
const ViewChangeRequest = (props) => {
};
export default withRouter(ViewChangeRequest);
非常感谢
完成route.js代码
[
{
path: '/',
exact: true,
title: 'Dashboard',
icon: 'dashboard',
breadcrumbs: ['Dashboard'],
contentComponent: UserDashboard,
isEnabled: () => true,
},
{
type: 'subMenu',
title: 'Codes and Guidelines',
children: [
{
path: '/LocalCodes',
exact: true,
title: 'Local Codes',
icon: 'dashboard',
breadcrumbs: ['Codes and Guidelines', 'Local Codes'],
contentComponent: AddLocalCode,
isEnabled: () => true,
},
],
},
{
type: 'subMenu',
title: 'Design Criteria',
children: [
{
path: '/Climate',
exact: true,
title: 'Climate',
icon: 'dashboard',
breadcrumbs: ['Design Criteria', 'Climate'],
contentComponent: ContentClimate,
isEnabled: () => true,
},
],
},
{
path: '/Viewchange/:id/:dataid',
title: 'Viewchange',
icon: 'dashboard',
breadcrumbs: ['dashboard'],
contentComponent: ViewChangeRequest,
isEnabled: () => false,
},
];
您需要使用反引号 (template literals) 来动态构建您的 url.
history.push(`/Viewchange?id=${record.id}&dataid=${record.dataid}`);
有两种构造动态Urls的方法:
- 使用字符串 -
history.push('/Viewchange?id=' + record.id + '&dataid=' + record.dataid);
- 使用 Bactick -
history.push(`/Viewchange?id=${record.id}&dataid=${record.dataid}`);
我正在尝试使用按钮单击事件中的历史对象将查询字符串参数发送到另一个页面,如下所示
const viewChange = (record) => {
debugger;
history.push('/Viewchange?id=record.id&dataid=record.dataid');
};
这是我在 routes.js 文件
中定义的路线{
path: '/Viewchange/:id/:dataid',
exact: true,
title: 'Viewchange',
icon: 'dashboard',
breadcrumbs: ['dashboard'],
contentComponent: ViewChangeRequest,
isEnabled: () => false,
},
一些我如何得到一个空白页面 url 下面
http://localhost:3000/Viewchange?id=record.id&dataid=record.dataid#
我不确定在这种情况下我哪里做错了,谁能告诉我如何将查询字符串值附加到 url 下面的代码是我要重定向的组件
const ViewChangeRequest = (props) => {
};
export default withRouter(ViewChangeRequest);
非常感谢
完成route.js代码
[
{
path: '/',
exact: true,
title: 'Dashboard',
icon: 'dashboard',
breadcrumbs: ['Dashboard'],
contentComponent: UserDashboard,
isEnabled: () => true,
},
{
type: 'subMenu',
title: 'Codes and Guidelines',
children: [
{
path: '/LocalCodes',
exact: true,
title: 'Local Codes',
icon: 'dashboard',
breadcrumbs: ['Codes and Guidelines', 'Local Codes'],
contentComponent: AddLocalCode,
isEnabled: () => true,
},
],
},
{
type: 'subMenu',
title: 'Design Criteria',
children: [
{
path: '/Climate',
exact: true,
title: 'Climate',
icon: 'dashboard',
breadcrumbs: ['Design Criteria', 'Climate'],
contentComponent: ContentClimate,
isEnabled: () => true,
},
],
},
{
path: '/Viewchange/:id/:dataid',
title: 'Viewchange',
icon: 'dashboard',
breadcrumbs: ['dashboard'],
contentComponent: ViewChangeRequest,
isEnabled: () => false,
},
];
您需要使用反引号 (template literals) 来动态构建您的 url.
history.push(`/Viewchange?id=${record.id}&dataid=${record.dataid}`);
有两种构造动态Urls的方法:
- 使用字符串 -
history.push('/Viewchange?id=' + record.id + '&dataid=' + record.dataid);
- 使用 Bactick -
history.push(`/Viewchange?id=${record.id}&dataid=${record.dataid}`);