I have a page where I have button, if users click on that button I am going to redirect to other page say (page 2) using the below function:
const viewChange = (record) => {
let path = `newPath`;
history.push('/ViewChangeRequest');
};
I want to pass some of the values to other page say record.id, record.name
but could not be able to figure it out the way we can pass these to other page..
My other page is looks like below:
const ViewChangeRequest = () => {
.....
......
......
};
export default ViewChangeRequest;
Could any one please suggest any ideas on how to redirect to other page along with the values and also retrieving those in page 2..
PS: I am using reactive functional components and hooks as well.
Many thanks in advance.
update:
i passed the props but getting an error like Cannot read property 'state' of undefined
const viewChange = (record) => {
history.push({
pathname: '/Viewchange',
state: { id: record.id, dataid: record.key },
});
};
page 2 : I am retrieving like this
const ViewChangeRequest = (props) => {
const { data: localCodeData, loading: localCodeDataLoading, error: localCodeDataError } = useQuery(GET_SPECIFICLOCALCODE, {
variables: { codeinputs: { id: props.location.state.dataid } },
});
const { data: requestData, loading: requestDataLoading, error: requestDataError
} = useQuery(GET_SPECIFICREQUEST, {
variables: { requestinputs: { id: props.location.state.id } },
});
return (
........
.......
);
};
export default ViewChangeRequest;
second update:
routes.js file
{
path: '/Viewchange/:id/:dataid',
title: 'Viewchange',
icon: 'dashboard',
breadcrumbs: ['dashboard'],
contentComponent: ViewChangeRequest,
isEnabled: () => false,
},
page 1:
const viewChange = (record) => {
debugger;
history.push(`/Viewchange?id=${record.id}&dataid=${record.key}`);
};
page 2
const ViewChangeRequest = (props) => {
};
export default withRouter(ViewChangeRequest);