Javascript 尝试使用reactJS将querystring参数发送到另一个页面
我正在尝试使用按钮单击事件中的history对象将querystring参数发送到另一个页面,如下所示Javascript 尝试使用reactJS将querystring参数发送到另一个页面,javascript,reactjs,react-router,router,Javascript,Reactjs,React Router,Router,我正在尝试使用按钮单击事件中的history对象将querystring参数发送到另一个页面,如下所示 const viewChange = (record) => { debugger; history.push('/Viewchange?id=record.id&dataid=record.dataid'); }; 这是我在routes.js文件中定义的路由 { path: '/Viewchange/:id/:dataid', exact: true, title
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,
},
一些我是如何得到一个空网页的网址如下
http://localhost:3000/Viewchange?id=record.id&dataid=record.dataid#
我不确定在这种情况下我哪里做错了,有人能告诉我如何将querystring值附加到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,
},
];
您需要使用backtick character()来动态构造url
history.push(`/Viewchange?id=${record.id}&dataid=${record.dataid}`);
有两种方法可以构造动态URL:
history.push('/Viewchange?id='+record.id+'&dataid='+record.dataid)代码>
它正在重定向到该页面,但它给出了一个空白页面,url如下
http://localhost:3000/Viewchange?id=34daf76e9e6043238bd1725a347af8d4&dataid=96a83572aec2425a8e8ee75afbf52bd3#
@EnigmaState它与您的路线定义相关。您可以添加react路由器dom路由定义吗?@EnigmaState这是路由的配置文件吗?你如何使用它?你能补充一下这个问题吗?让我们谈谈。
history.push(`/Viewchange?id=${record.id}&dataid=${record.dataid}`);