[英]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 }
,以便AboutContainer
和PagesContainer
出現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.