React路由器1.0.0-beta3无法正常工作

时间:2015-07-17 12:18:01

标签: javascript reactjs browserify react-router

我做错了吗?当我转到此网址http://localhost:7000/#/about

时,不会呈现this.props.children

- //文件名:main.js

import React from 'react';
import { Router, Route, Link } from 'react-router';
import { history } from 'react-router/lib/BrowserHistory';

import Wrapper from "./components/Wrapper.react";
import ThumbnailContainer from './components/ThumbnailContainer.react';

React.render((
  <Router history={history}>
    <Route path="/" component={Wrapper}>
        <Route path="/about" components={ThumbnailContainer}>
        </Route>
    </Route>
  </Router>
), document.body);

- //文件名:Wrapper.react.js

var Wrapper = React.createClass({
    getInitialState: function() {
        return(
            {
               className : "p-wrapper p-blue-theme"
            }
        );
    },
    render: function () {
        return(
          <div className={this.state.className} >
              {this.props.children}
          </div>
        );
    }
});

exports['default'] = Wrapper;
module.exports = exports['default'];

- //文件名:ThumbnailContainer.react.js

var React = require('react');
var ThumbnailContainer = React.createClass({
    render: function(){
        return (
            <div className="p-thumbnail-container">
            <a className="p-thumbnail" href="#">
                    <div className="p-thumbnail-img-container"> 
                        <img src="http://placehold.it/200x200" className="p-thumbnail-img" />
                    </div>
                    <div className="p-thumbnail-caption">
                        <h3 className="p-title">Thumbnail Title</h3>
                        <h4 className="p-sub-title">Thumbnail Sub Title</h4>
                        <p className="p-description">Thumbnail Description Lorem Ipsum</p>
                    </div>
            </a>
        </div>
        );
    }
});

module.exports = ThumbnailContainer;

2 个答案:

答案 0 :(得分:1)

将components = {ThumbnailContainer}更改为组件 = {ThumbnailContainer}。

答案 1 :(得分:0)

尝试从'/ about'中删除'/'。路由是嵌套的,所以我认为'/'默认路由后的前导'/'是多余的。如果有效,请告诉我们。