简体   繁体   中英

React router not working

I have a simple react-router setup. Please see my code here -

https://github.com/rocky-jaiswal/lehrer-node/tree/master/frontend

It is the most basic setup for react-router, however in the browser I cannot get it working -

import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route } from 'react-router';
import IndexContainer from './components/index-container';
import AboutContainer from './components/about-container';
import PagesContainer from './components/pages-container';

(function main() {
  ReactDOM.render((
    <Router>
      <Route path="/" component={IndexContainer}>
        <Route path="about" component={AboutContainer} />
        <Route path="pages" component={PagesContainer} />
      </Route>
    </Router>),
    document.getElementById('app')
  );
})();

The trouble also is there is no error reported on the console. Even I change the URL the IndexComponent is always mounted. Also if I type http://localhost:3333/#/about it changes to http://localhost:3333/#/about?_k=bac2pt somehow and stays on the IndexComponent.

Could there be something wrong with my simple webpack config or versions of react / react-router?

Thanks, Rocky

IndexContainer是您的父组件,请尝试在您的render()添加{ this.props.children } ,以便AboutContainerPagesContainer出现。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM