React Router v4 不显示组件

React Router v4 not displaying components

当我导航到 localhost:3000/signup 时,组件没有显示 是因为 React 路由器更新到 v4 并且它们在 React 中的路由方式现在已经改变了吗?

我有我的 main.js 文件

import Signup from '../imports/ui/Signup';

import
const routes = (
  <Router history={browserHistory}>
    <Route path="/signup" component={Signup}/>
  </Router>
);

注册组件

import React from 'react';

export default class Signup extends React.Component {
  render() {
    return <p>Signup</p>
  }
}

我正在使用 react router v4,也在使用 Meteor。

React Router v4 是 React Router 的重写,因此您必须阅读新的 API 并相应地调整您的代码。我建议浏览所有可以找到的示例 here。这是看起来与您的代码相似的基本示例。您会注意到的最重要的事情是您不再拥有集中式路由配置。相反,您可以在需要时动态呈现 ``。

import React from 'react'
import {
  BrowserRouter as Router,
  Route,
  Link
} from 'react-router-dom'

const BasicExample = () => (
  <Router>
    <div>
      <ul>
        <li><Link to="/">Home</Link></li>
        <li><Link to="/about">About</Link></li>
        <li><Link to="/topics">Topics</Link></li>
      </ul>

      <hr/>

      <Route exact path="/" component={Home}/>
      <Route path="/about" component={About}/>
      <Route path="/topics" component={Topics}/>
    </div>
  </Router>
)

const Home = () => (
  <div>
    <h2>Home</h2>
  </div>
)

const About = () => (
  <div>
    <h2>About</h2>
  </div>
)

const Topics = ({ match }) => (
  <div>
    <h2>Topics</h2>
    <ul>
      <li>
        <Link to={`${match.url}/rendering`}>
          Rendering with React
        </Link>
      </li>
      <li>
        <Link to={`${match.url}/components`}>
          Components
        </Link>
      </li>
      <li>
        <Link to={`${match.url}/props-v-state`}>
          Props v. State
        </Link>
      </li>
    </ul>

    <Route path={`${match.url}/:topicId`} component={Topic}/>
    <Route exact path={match.url} render={() => (
      <h3>Please select a topic.</h3>
    )}/>
  </div>
)

const Topic = ({ match }) => (
  <div>
    <h3>{match.params.topicId}</h3>
  </div>
)

export default BasicExample