您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
完整代码:
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。