react-router-dom页面跳转带参数,刷新不消失
原页面:
import { useHistory } from 'react-router-dom';
const history = useHistory();
const onViewDetail = async (item) => { const sourceParserNodeData = { id: item.id, name: item.name, }; localStorage.setItem( 'sourceParserNodeData', JSON.stringify(sourceParserNodeData) ); history.push(`/admin/blockParseManage/chainParser`, { sourceParserNodeData, }); };
目的页面:
import { useLocation } from 'react-router-dom';
const location = useLocation(); console.log('ccc----', location) const pnData = location.state?.sourceParserNodeData ?? ''; const parserNodeId = pnData.id || ''; const parserNodeName = pnData.name || '';