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 || '';

 

posted @ 2024-12-04 17:21  走走停停走走  Views(20)  Comments(0Edit  收藏  举报