React router v4 error" Uncaught ReferenceError:Router未定义"

时间:2017-02-11 13:32:32

标签: javascript reactjs spring-boot react-router react-router-v4

我正在使用react-router v4进行项目 这是我的CDN

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/4.0.0-alpha.3/react-router.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.38/browser.min.js"></script>

这是我的代码

ReactDOM.render(

  <Router>
  <Route path="/" component={LoginForm} />
        </Router>

    ,document.getElementById('root'));
</script>

loginform代码如下所示

var LoginForm = React.createClass({
render: function() {
return (
    <div> 
    <div id="postdiv">
<form id="customerForm" data-toggle="validator">
<div className="form-group">
<span className="label label-default">Login</span>
...

我收到此错误

Uncaught ReferenceError: Router is not defined
at eval (eval at n.run (browser.min.js:3), <anonymous>:79:3)
at Function.n.run (browser.min.js:3)
at l (browser.min.js:3)
at i (browser.min.js:3)

1 个答案:

答案 0 :(得分:0)

当您import react-router cdn时,您可以像

一样使用它
    <ReactRouter.Router>
       <ReactRouter.Route path="/" component={LoginForm} />
    </ReactRouter.Router>

同样来自您的评论,您似乎未导出LoginForm组件或未正确导入

您需要执行以下操作

var LoginForm = React.createClass({
render: function() {
return (
    <div> 
    <div id="postdiv">
<form id="customerForm" data-toggle="validator">
<div className="form-group">
<span className="label label-default">Login</span>
...
)}
})

export default LoginForm;

您还需要像

一样导入它
<script src="path/to/loginFormFile"></script>