繁体   English   中英

反应路由器不工作

[英]React router not working

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

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

这是react-router的最基本设置,但是在浏览器中我无法正常运行-

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 / react-router版本可能有问题吗?

谢谢,洛基

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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