React路由器不工作

React router not working

本文关键字:工作 路由器 React      更新时间:2023-09-26

我有一个简单的react路由器设置。请在这里查看我的代码-

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

这是react路由器最基本的设置,但在浏览器中我无法使其工作-

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')
  );
})();

问题还在于控制台上没有报告错误。即使我更改了URL,IndexComponent也始终被挂载。如果我输入http://localhost:3333/#/about它更改为http://localhost:3333/#/about?_k=bac2pt以某种方式并停留在IndexComponent上。

我的简单webpack配置或react/areact路由器的版本是否有问题?

谢谢,Rocky

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