【问题标题】:React Router Params not working反应路由器参数不起作用
【发布时间】:2017-05-30 14:03:38
【问题描述】:

我正在尝试在我的 react redux 应用程序中使用参数,但不幸的是它不起作用。我得到一个空白屏幕。这是我正在关注的代码

import React from 'react';
import ReactDOM from 'react-dom';
import {Router, Route, browserHistory} from 'react-router';
import thunk from 'redux-thunk';
import rootReducer from './rootReducer';
import { createStore, applyMiddleware, compose } from 'redux';

 const store = createStore(
 rootReducer,
 compose(
   applyMiddleware(thunk),
   window.devToolsExtension ? window.devToolsExtension() : f => f
 )
);
ReactDOM.render(
<Provider store={store}>
<Router history={browserHistory}>
  <Route path="/" component={Login}/>
  <Route path="/lists" component={requireAuth(Dashboard)}/>
  {/* Parameter route*/}
  <Route path="/record/:mEID" component={requireAuth(Record)}/>
</Router>
</Provider>,
document.getElementById('root')
);

当我转到我的本地主机 URL 时,即 localhost:3000/record/16655 然后我收到类似“http://localhost:3000/record/index.js 未找到”的错误。

有什么办法可以解决这个问题???

这是我的 package.json 供参考

 "lodash": "^4.17.4",
 "prop-types": "^15.5.10",
"react": "^15.1.0",
"react-bootstrap": "^0.31.0",
"react-bootstrap-table": "^3.3.7",
"react-dom": "^15.1.0",
"react-fontawesome": "^1.6.1",
"react-redux": "^4.4.5",
"react-router": "^3.0.2",
"redux": "^3.5.2",
"redux-thunk": "^2.1.0",

【问题讨论】:

  • 你最终解决了这个问题吗?

标签: reactjs react-router react-redux


【解决方案1】:

尝试像这样嵌套你的路线

...

<Route path='/record' ...>
  <Route path='/:meid' ../>
</Route>

基于React-router tutorial#nested-routes

<App>       {/*  /          */}
  <Repos>   {/*  /repos     */}
    <Repo/> {/*  /repos/123 */}
  </Repos>
</App>

【讨论】:

    猜你喜欢
    • 2016-12-04
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 2019-11-15
    • 1970-01-01
    • 2015-11-25
    • 2017-02-24
    相关资源
    最近更新 更多