我正在为我的项目使用React Router,但无法弄清楚为什么不能将参数传递到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中正确打开它,但网址是这样的:
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
组件的更多信息
这应该有帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句