React-router v4.1.1仅适用于dev-server

时间:2017-06-26 11:21:23

标签: javascript reactjs react-router-v4

我正在尝试将我的反应项目放入gh页面。但我发现了 当我捆绑时,反应路由器将无法令人惊讶地工作 反应代码。它在dev-server中运行得很好

以下是我的主要组件和Index.js的代码

import React from 'react';
import ReactDOM from 'react-dom';
import FrontPage from './FrontPage.js';
import Page from './Page.js';
import Courses from './Courses.js'
import Register from './Register.js'
import "../assets/css/index.css";
import { Router, Route ,Switch} from 'react-router'
import { HashRouter,IndexRoute} from 'react-router-dom'

class Main extends React.Component {
    componentDidMount(){

    }
    render() {
        return (
            <div>
                <Page>
                    <Route exact path = '/' component = {FrontPage} />
                    <Route path = '/course' component = {Courses}/>
                    <Route path = '/register' component = {Register}/>
                </Page>
            </div>
        );
  }
}

export default Main;

这是index.js

import React from 'react'
import { render } from 'react-dom'
import { Router, Route ,Switch} from 'react-router'
import { HashRouter,IndexRoute, BrowserRouter} from 'react-router-dom'
import Main from './components/Main.js';



render((
  <BrowserRouter>
    <Route path = '/' component = {Main}/>
  </BrowserRouter>
), document.getElementById('root'))

这里是项目的github

https://github.com/supasonk/ExampleTutor

更新:我已经发现了问题。看起来GitHub页面与BrowserRouter不兼容。我通过使用Hashrouter来实现它。

0 个答案:

没有答案