Define query param in Link, accept path and query :
const Links = () => <nav > <Link to={{path: ‘/‘, query: {message: ‘Yo‘}}}>Home</Link> </nav>;
Use Query param by props.location.query:
const Container = (props) => <div>{props.location.query.message || ‘Hello‘}<Links /></div>;
-----------------------
import React from ‘react‘; import {hashHistory, Route, Router, Link, IndexRoute} from ‘react-router‘; const Container = (props) => <div>{props.location.query.message || ‘Hello‘}<Links /></div>; const Links = () => <nav > <Link to={{path: ‘/‘, query: {message: ‘Yo‘}}}>Home</Link> </nav>; class App extends React.Component { render(){ return( <Router history={hashHistory}> <Route path="/" component={Container}></Route> </Router> ); } } export default App;
时间: 2024-11-05 19:00:11