[英]react-router router.push doesn't fire componentWillMount
我在react-router上遇到問題。 我在頁面“ / portal / clients // systems // configure”上,並且在刪除系統時想將頁面更改為“ / portal / clients // systems”。
我正在使用react-rouer的withRouter來訪問路由器,並且執行了router.push,但是“ / portal / clients // systems”頁面沒有被重新加載。 componentWillMount根本不會被解雇。
我要解決這個錯誤嗎?
app.js:
const SystemConfigureAsync = (nextState, cb) => {
require.ensure([], require =>
cb(null, require('./modules/systems/SystemConfigure.jsx')
));
};
const App = () => (
<Router history={browserHistory}>
<Route path="/portal" component={Container} onEnter={redirector.checkRequirements}>
<Route path="clients/:org">
<Route path="systems" getComponent={SystemsAsync}>
<Route path=":system_id" getComponent={SystemAsync}>
<Route path="configure" getComponent={SystemConfigureAsync} />
</Route>
</Route>
</Route>
<Route path="*" component={NotFound} />
</Router>
);
./modules/systems/SystemConfigure.jsx:
const React = require('react');
const { withRouter } = require('react-router');
const SystemConfigure = withRouter(React.createClass({
render() {
const { org: orgId } = this.props.params;
const { router } = this.props;
return (
<ContentSpinner loadingMessage="Loading System" loading={this.state.isLoading}>
<ConfigureSystem
systemId={this.state.model.get('system_id')}
model={this.state.model}
deleteable={this.state.model.get('deletable')}
onDelete={() => {
router.push(`/portal/clients/${orgId}/systems`);
}}
/>
</ContentSpinner>
);
},
}));
module.exports = SystemConfigure;
豹的評論很有幫助。
我添加了路線:
<Route path="systems/delete-system/:delete_system_id" getComponent={SystemsAsync} />
這就是componentWillReceiveProps的樣子:
componentWillReceiveProps(nextProps) {
const { router } = this.props;
const { org: orgId, delete_system_id } = nextProps.params;
if (delete_system_id) {
this.setState({ systemishes: reject(this.state.systemishes, sys => sys.system_id === delete_system_id) });
router.push(isMsp() ? `/portal/partners/${orgId}/systems` : `/portal/clients/${orgId}/systems`);
}
},
現在就像魅力一樣
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.