您好,登錄后才能下訂單哦!
完整代碼:
var React = require('react')
var ReactDom = require('react-dom')
var ReactRouter = require('react-router-dom')
var Router = ReactRouter.BrowserRouter
var Route = ReactRouter.Route
var Link = ReactRouter.Link
var browserHistory = ReactRouter.browserHistory
var CreateClass = require('create-react-class')
var PropTypes = require('prop-types')
var Index = CreateClass({
render:function(){
return (
<Router history={browserHistory}>
<div>
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/about">About</Link></li>
<li><Link to="/docs">Docs</Link></li>
</ul>
<hr/>
<Route exact path="/" component={Home}/>
<Route path="/about" component={About}/>
<Route path="/docs" component={Docs}/>
<Route path="/step1" component={Step1}/>
</div>
</Router>
)
}
})
var Home = CreateClass({
render:function(){
return(
<div>
<h3>Home</h3>
</div>
)
}
})
var About = CreateClass({
render:function(){
return(
<div>
<h3>About</h3>
</div>
)
}
})
var Docs = CreateClass({
render:function(){
return(
<div>
<ul>
<li><Link to="/step1">Step1</Link></li>
</ul>
<hr/>
<Route exact path="/step1" component={Step1}/>
</div>
)
}
})
var Step1 = CreateClass({
onClick:function(){
var history = this.props.history
history.push('/')
},
render:function(){
return(
<div>
<span onClick={this.onClick}>回到主頁</span>
<h3>Step1</h3>
</div>
)
}
})
ReactDom.render((
<Index/>
), document.body)
var ReactRouter = require('react-router-dom')
var withRouter = ReactRouter.withRouter
b. 使用:
this.props.history.push("/")
c. 導出:
module.exports = withRouter(Login)
var Router = ReactRouter.HashRouter
b. 使用:
<Router>
<LocaleProvider locale={Cn}>
<div className="index_container">
<Head/>
<Route exact path="/" component={Home}/>
<Route path="/home" component={Home}/>
<Route path="/login" component={Login}/>
<Route path="/system" component={System}/>
<Route path="/user" component={User}/>
<Foot/>
<Write/>
</div>
</LocaleProvider>
</Router>
var Switch = ReactRouter.Switch
b. 定義:
<Switch>
<Route exact path="/some/path" component={XXX}/>
<Route path="*" component={Notfound}/>
</Switch>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。