30_react_router基本使用
Posted zhanzhuang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了30_react_router基本使用相关的知识,希望对你有一定的参考价值。
项目结构:
import React from ‘react‘ import {render} from ‘react-dom‘ import {BrowserRouter} from ‘react-router-dom‘ import App from ‘./components/app‘ render( ( <BrowserRouter> <App/> </BrowserRouter> ), document.getElementById(‘root‘) )
import React, {Component} from ‘react‘ import {NavLink, Switch, Route, Redirect} from ‘react-router-dom‘ import About from ‘../views/about‘ import Home from ‘../views/home‘ export default class App extends Component { render() { return ( <div> <div className=‘row‘> <div className=‘col-xs-8 col-xs-offset-2‘> <div className=‘page-header‘> <h2>React Router Demo</h2> </div> </div> </div> <div className=‘row‘> <div className=‘col-xs-2 col-xs-offset-2‘> <div className=‘list-group‘> <NavLink className=‘list-group-item‘ to=‘/about‘>about</NavLink> <NavLink className=‘list-group-item‘ to=‘/home‘>home</NavLink> </div> </div> <div className=‘col-xs-6‘> <div className=‘panel‘> <div className=‘panel-body‘> <Switch> <Route path=‘/about‘ component={About}/> <Route path=‘/home‘ component={Home}/> <Redirect to=‘/home‘/> </Switch> </div> </div> </div> </div> </div> ); } }
import React, {Component} from ‘react‘ export default class About extends Component { render() { return ( <div> about route component </div> ) } }
import React, {Component} from ‘react‘ export default class Home extends Component { render() { return ( <div> home route component </div> ) } }
以上是关于30_react_router基本使用的主要内容,如果未能解决你的问题,请参考以下文章
转载---编写高质量代码:改善Java程序的151个建议(第2章:基本类型___建议26~30)
精心收集的 48 个 JavaScript 代码片段,仅需 30 秒就可理解