路由反应路由器不工作

时间:2017-05-04 12:00:20

标签: javascript reactjs react-router

我创建了一些组件。对于路由,我使用的是react-router-dom。我的设置如下。

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';

import Dashboard from './components/Dashboard.jsx';
import Login from './components/Login.jsx';
import Signup from './components/Signup.jsx';
import Application from './components/Application.jsx';

import "./assets/main.css"

ReactDOM.render(
    <Router>
        <Application>
            <Switch>
                <Route exact path="/" component={Dashboard} />
                <Route path="login" component={Login} />
                <Route path="/signup" component={Signup} />
            </Switch>
        </Application>
    </Router>, document.getElementById('container')
);

此处我唯一的'/'路线正常运行,对于/login/signup我得到Cannot GET /signup

请帮我从这里出来。在期待中感谢

1 个答案:

答案 0 :(得分:0)

您应该在history={browserHistory}中使用<Router>。您的代码应如下所示:

<Router history={browserHistory}>

<强>更新

您应该在webpack.config.js;

中添加以下内容
devServer: {
  historyApiFallback: true
}