You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to pass 2 properties using history.push({generatePath: ... }) from React Router. Unfortunatelly the way I pass it allows to read only first property 'from':
const handlePushToTrainDetails = (trainId: string) => {
history.push({
pathname: generatePath(Routes.TrainDetails.path, {
idTrain: trainId,
}),
state: {
from: history.location.pathname,
shouldGoBackToMapScreen:
'shouldGoBackToMapScreen',
},
});
};
In rendered component I have :
const location = useLocation();
console.log(location.state);
In the console I can see only first property 'from' second one don't exist there.
How I should fix it ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello.
I want to pass 2 properties using history.push({generatePath: ... }) from React Router. Unfortunatelly the way I pass it allows to read only first property 'from':
const handlePushToTrainDetails = (trainId: string) => {
history.push({
pathname: generatePath(Routes.TrainDetails.path, {
idTrain: trainId,
}),
state: {
from: history.location.pathname,
shouldGoBackToMapScreen:
'shouldGoBackToMapScreen',
},
});
};
In rendered component I have :
const location = useLocation();
console.log(location.state);
In the console I can see only first property 'from' second one don't exist there.
How I should fix it ?
Beta Was this translation helpful? Give feedback.
All reactions