[英]Change react router route params programmatically
是否有任何简单方便的方法可以使用不同的参数导航到相同的路线?
例如。 我现在在 /profile/idan 上,我希望立即将idan
的参数idan
为其他内容,而无需处理路由的静态部分。
如果您的问题是关于 API 的 v3,则react-router
库引入了router
上下文。 如果您在contextTypes
声明,您将可以访问推送和替换方法。 例子:
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.