我的应用程序中有一个组件是一种形式。该表格用于创建新许可证或编辑现有许可证。无论哪种方式,它都是一个组件,并检查componentDidMount()是哪个“ pageType”(添加/更新)。现在我要解决的问题是,当我使用表单来编辑许可证(被许可人/:id /编辑),并且单击作为坐浴盆的按钮来创建新许可证(被许可人/添加)时,它不会重新安装零件。它将更改URL,但所有预加载的数据仍处于表单中。
LicenseeForm = Loadable({
loader: () => import('./license/LicenseeForm'),
loading: 'Loading..'
});
render() {
return (
<Router>
<Switch>
<LoginRoute exact path="/" component={this.LoginView}/>
<LoginRoute exact path="/login" component={this.LoginView}/>
<PrivateRoute exact path="/licensees/add" component={this.LicenseeForm}/>
<PrivateRoute exact path="/licensees/:id/update" component={this.LicenseeForm}/>
<Route path="*" component={this.NotFoundPage}/>
</Switch>
</Router>
)
}
const PrivateRoute = ({component: Component, ...rest}) => (
<Route
{...rest}
render={props =>
authService.checkIfAuthenticated() ? (<Component {...props} />) :
(<Redirect
to={{
pathname: "/login",
state: {from: props.location}
}}/>
)
}
/>
);
Run Code Online (Sandbox Code Playgroud)
零件:
componentDidMount() {
const locationParts = this.props.location.pathname.split('/');
if …Run Code Online (Sandbox Code Playgroud)