当索引路由

时间:2016-11-15 09:26:29

标签: reactjs nginx react-router

我在index.js文件中设置了简单的路由。

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import { Router, Route, IndexRoute, browserHistory } from 'react-router';

import reduxThunk from 'redux-thunk';

import '../less/app.less';

import reducers from './reducers';

import App from './components/App';
import Login from './components/auth/Login';
import Welcome from './components/Welcome';

// const defaultSetting = settings;
const createStoreWithMiddleware = applyMiddleware(reduxThunk)(createStore);

ReactDOM.render(
  <Provider store={createStoreWithMiddleware(reducers)}>
    <Router history={browserHistory}>
      <Route path="/" component={App}>
        <IndexRoute component={Welcome} />
        <Route path="login" component={Login} />
      </Route>
    </Router>
  </Provider>
  , document.querySelector('.container')
);

我的App.js

import React, { Component } from 'react';

class App extends Component {
    render() {
        return (
            <div>
                {this.props.children}
            </div>
        );
    }
}

export default App;

我已经尝试更改我的nginx配置(网站可用):

location / {
    try_files $uri $uri/ /index.html;
}

当我使用宅基地导航到admin.example.dev时,我可以正确显示我的索引路线。但是当我导航到admin.example.dev/login it shows error index.js:24421 Warning: [react-router] Location "/login" did not match any routes时。

任何解决方案?

0 个答案:

没有答案