gpt4 book ai didi

javascript - 尝试使用reactJS将查询字符串参数发送到另一个页面

转载 作者:行者123 更新时间:2023-12-02 22:17:37 24 4
gpt4 key购买 nike

我正在尝试使用按钮单击事件中的历史对象将查询字符串参数发送到另一个页面,如下所示

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#

我不确定在这种情况下我哪里做错了,任何人都可以让我知道如何将查询字符串值附加到网址下面的代码是我要重定向的组件

 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 ) 来动态构建您的网址。

history.push(`/Viewchange?id=${record.id}&dataid=${record.dataid}`);

关于javascript - 尝试使用reactJS将查询字符串参数发送到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59337702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com