这是我想要实现的示例代码。但是我找不到反应没有渲染组件的原因。我在CDN中包含react-router。请帮忙
import { Router, Route, Link, browserHistory } from 'react-router'
var HomePage = React.createClass({
render:function(){
return(
<div>
<h1>Hi World</h1>
</div>
);
}
});
ReactDOM.render(
<Router history={browserHistory}>
<Route path='/home' component={HomePage} />
</Router>
,document.getElementById('mydiv')
);
答案 0 :(得分:1)
尝试使用hashHistory ,jsbin example with CDN。
browserHistory 要求服务器端additional configuration提供网址。
var ReactRouter = window.ReactRouter;
var Route = ReactRouter.Route;
var Router = ReactRouter.Router;
var Link = ReactRouter.Link;
var hashHistory = ReactRouter.hashHistory;
var HomePage = React.createClass({
render:function(){
return(
<div>
<h1>Hi World</h1>
</div>
);
}
});
ReactDOM.render(
<Router history={hashHistory}>
<Route path='/home' component={HomePage} />
</Router>
,document.getElementById('mydiv')
);