配置脚手架
$ create-react-app
App.js
import React from 'react'; import { BrowserRouter as Router,Route,withRouter,Switch} from 'react-router-dom'; import Home from './Home'; import Page1 from './Page1'; import Page2 from './Page2'; class App extends React.Component { render(){ return( <Router> <div> <Route exact path="/" component={Home} /> <Route path="/Page1" component={Page1} /> <Route path="/Page2" component={Page2} /> <Route path="/Page3" component={Page3} /> </div> </Router> ) } } export default App;
Home.js
import React from 'react'; import { Link } from 'react-router-dom'; class Home extends React.Component{ render(){ return( <div> <div>This is Home!</div> <div> <Link to="/Page1/">点击</Link> </div> </div> ); } } export default Home;
Page1.js
import React from 'react'; import { Link } from 'react-router-dom'; class Page1 extends React.Component{ render(){ return( <div> <div className="p1">This is Page1!</div> <div> <Link to="/Page2/">点击跳转到Page2</Link> </div> </div> ); } } export default Page1;
Page2.js
省略
index.js
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; ReactDOM.render(<App/>, document.getElementById('root'));
点击查看更多内容
2人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦