反应路由器无法传递参数

React router can't pass params

我正在为我的项目使用 React 路由器,但我不明白为什么我不能将参数传递到我的 Url。

这里我定义了我的路线:

render(
  <Provider store={store}>
      <Router history={browserHistory}>
          <Route path="/" component={App}>
              <Route path="home" >
                  <Route path="editor/:id" component={EditorContainer}/>
              </Route>
          </Route>
      </Router>
  </Provider>,
  document.getElementById('root')
);

在我的组件中有这一行:

<Link to="/home/editor/:id" params={{id: elem.id}}
                                                 onClick = {onOpen}>{elem.title} </Link>

在 EditorContainer 中打开我的元素

它在我的 EditorContainer 中正确打开它,但 url 是这样的:

http://localhost:8080/home/editor/:id

不喜欢例如:

http://localhost:8080/home/editor/1234

你能告诉我我做错了什么吗?

将您的组件更改为:

var link='/home/editor' + elem.id;
<Link to={link} />

您可以查看 React-Router Link 以获取有关 Link 组件

的更多信息

这应该有帮助