[英]Change react router route params programmatically
Is there any simple and convenient way to navigate to same route with different params?是否有任何简单方便的方法可以使用不同的参数导航到相同的路线?
for ex.例如。 I'm right now on /profile/idan and I wish to change the param of
idan
to something else, instantly without dealing with the static part of the route.我现在在 /profile/idan 上,我希望立即将
idan
的参数idan
为其他内容,而无需处理路由的静态部分。
If your question is about v3 of the API, the react-router
library introduces a router
context.如果您的问题是关于 API 的 v3,则
react-router
库引入了router
上下文。 If you declare that in your contextTypes
, you'll have access to a push and replace method.如果您在
contextTypes
声明,您将可以访问推送和替换方法。 Example:例子:
import React, { Component, PropTypes } from 'react';
import { PropTypes as RouterPropTypes } from 'react-router';
class MyComponent extends Component {
// ...
handleSomeEvent() {
this.context.router.push('/some/url');
}
}
MyComponent.contextTypes = {
router: RouterPropTypes.routerShape
};
export default MyComponent;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.