【问题标题】:Can't get latest react-router working无法让最新的反应路由器工作
【发布时间】:2014-11-22 15:37:33
【问题描述】:

我升级到react-router 的最新版本 0.7.0,但无法正常工作。我不确定这是否是我的 Require 语句,我从其中一个路由器示例中复制了它们。

我正在使用: watchify --debug -t reactify ./app.jsx -o ./build/app-brow.j

当我删除 react-router 代码时,下面的代码会通过 NPM 模块做出反应:

我在本地有这些 NPM 模块。 watchify 全局安装:

npm install react-router
npm install reactify
npm install react

app.jsx

/** @jsx React.DOM */

var React = require('react');

// React Router
var Router = require('react-router');
var Route = Router.Route;
var Routes = Router.Routes;
var Link = Router.Link;


var MyAboutView = React.createClass({
  render: function() {
    return (
      <div >
         My About
      </div>
    );
  }
});


var App = React.createClass({
   render: function() {
      return (
         <div>
            Main App

            <this.props.activeRouteHandler/>
         </div>
      );
  } 
}); 


React.renderComponent((
  <Routes>

    <Route path="/" handler={App}>
      <Route name="about" handler={myAboutView} />
    </Route>

  </Routes>
), document.body);

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Test Router</title

  </head>

  <body>
    Error, React / JS not loading.

    <script type="text/javascript" src="build/app-brow.js"></script>

  </body>
</html>

【问题讨论】:

  • 错误信息是什么意思?
  • 浏览器控制台错误显示:Uncaught ReferenceError: myAboutView is not defined.

标签: reactjs react-router


【解决方案1】:

我傻了,这是一个错字 handler={myAboutView} 应该是 handler={MyAboutView},注意 MyAboutView 上的 CAP。

【讨论】:

    猜你喜欢
    • 2017-08-04
    • 1970-01-01
    • 2017-11-09
    • 2019-06-17
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 2017-03-15
    • 1970-01-01
    相关资源
    最近更新 更多