React-router不呈现组件

时间:2016-07-07 08:53:56

标签: javascript reactjs react-router url-routing

这是我想要实现的示例代码。但是我找不到反应没有渲染组件的原因。我在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')

);

1 个答案:

答案 0 :(得分:1)

尝试使用hashHistory jsbin example with CDN

Example with imports

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')

);