我想使用browserHistory並向路徑添加參數,但是當向我的路徑添加參數時,我無法找到頁面,因爲瀏覽器所在的路徑不正確,因爲它會在網址前添加「AddAmendLeague」。browserHistory:反應路由器找不到路徑
(http://localhost:8080/Home)的路徑應該是什麼:
(http://localhost:8080/AddAmendLeague/1)現在的瀏覽器無法找到我的client.js:
ReactDOM.render(<Router history={browserHistory }>
<Route path='*' component={Layout}>
<IndexRoute component={Home}/>
<Route path="LeagueList" component={LeagueList}/>
<Route path="/AddAmendLeague/:LeagueID" component={AddAmendLeague}/>
</Route>
</Router>, app);
指數.html
<script src="client.min.js"></script>
關於我在做什麼的錯誤?對不起,如果這是一個愚蠢的錯誤。
不太清楚,如果你需要我的package.json
的package.json
{
"name": "bableandtypescript",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack-dev-server --content-base src --inline --hot --watch --history-api-fallback"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.17.0",
"babel-loader": "^6.2.5",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.16.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"debug": "^2.3.2",
"es6-promise": "^4.0.5",
"flux": "^3.0.0",
"history": "^4.3.0",
"json-loader": "^0.5.4",
"mysql": "^2.12.0",
"net": "^1.0.2",
"radium": "^0.18.1",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-router": "^2.8.1",
"undebug": "^1.0.0",
"webpack": "^1.13.2",
"webpack-dev-server": "^1.16.2",
"websocket": "^1.0.23"
}
}
嗨,hashHistory確實工作,但我試圖保持漂亮的URL和browserhistory提供。瀏覽器歷史路線的工作與散列歷史不同嗎? –
根據你的問題,似乎這行代碼不清楚。 這一行說你會去AddAmendLeague並且有一個叫做LeagueID的參數。我不理解你的問題嗎? –
如果你想要browserHistory的好網站,你也應該配置你的服務器(https://github.com/ReactTraining/react-router/blob/master/docs/guides/Histories.md#configuring-your-server) –