我有一个PageBuilder组件,可以根据配置文件动态构建编辑/列表页面.我想要使用相同的PageBuilder组件的动态路由(如"/ collection/list","/ collection/edit/123123","/ dashboard"等).我无法让它工作 - 例如,如果我在/ collection/list中,当点击指向/ collection/edit/1231的链接时不起作用.只刷新该URL工作(反之亦然).我尝试将初始化代码设置为PageBuilder,componentWilLReceiveProps但它似乎每秒都调用它.我的路线看起来像这样:
<Route path="/" component={App}>
<IndexRedirect to="/dashboard" />
<Route path="/:page/:collection/:action(/:entity_id)" component={PageBuilder} />
<Route path="/:page" component={PageBuilder} />
</Route>
而我的PageBuilder:
constructor(props) {
super(props);
this.createSectionsHTML = this.createSectionsHTML.bind(this);
this.onChange = this.onChange.bind(this);
this.onSave = this.onSave.bind(this);
}
getPageName() {
return this.props.params.page.replace(/-/g, '_').toLowerCase();
}
componentWillReceiveProps(props) {
this.action = this.props.params.action;
}
componentWillMount() {
let pageName = this.getPageName();
this.props.dispatch(setInitialItem(pageName));
}
componentDidMount() {
let pageName = this.getPageName();
let { collection, entity_id } = this.props.params;
if (collection && entity_id) {
let { dispatch …Run Code Online (Sandbox Code Playgroud)