简体   繁体   English

React Router无法传递参数

[英]React router can't pass params

I m using react router for my project but I can't figure out why I can't pass a parameter into my Url. 我正在为项目使用React Router,但无法弄清楚为什么不能将参数传递到Url中。

Here I defined my routes : 在这里,我定义了路线:

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')
);

In my component I have this line: 在我的组件中,有以下行:

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

To open my element in the EditorContainer 在EditorContainer中打开我的元素

It open it correctly in my EditorContainer but the url is like this : 它可以在我的EditorContainer中正确打开它,但网址是这样的:

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

and not like for example : 而不像例如:

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

Can you tell me what I m doing wrong please ? 你能告诉我我在做什么错吗?

Change your component to: 将组件更改为:

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

You can check React-Router Link to get more info about Link component 您可以检查React-Router Link以获取有关Link组件的更多信息

This should help 这应该有帮助

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

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