Javascript 如何在组件安装中更改路由

Javascript 如何在组件安装中更改路由,javascript,reactjs,react-redux,routes,components,Javascript,Reactjs,React Redux,Routes,Components,我在render中使用此代码来显示标题。需要将此逻辑移动到装载事件。如何做到这一点 render() { const viewPage = this.props.history.location.pathname.includes("/app/accountManagers/view/") const editPage = this.props.history.location.pathname.includes("/app/accountManagers/edit/")

我在render中使用此代码来显示标题。需要将此逻辑移动到装载事件。如何做到这一点

  render() {
     const viewPage = this.props.history.location.pathname.includes("/app/accountManagers/view/")
     const editPage = this.props.history.location.pathname.includes("/app/accountManagers/edit/")
     const newPage = this.props.history.location.pathname.includes("/app/accountManagers/new/")


        return (<div >
                <div className="app-wrapper">
                    <ContainerHeader match={this.props.match} title={<IntlMessages id={editPage ? "DIC_ADMIN_SETTINGS_ACCOUNT_MANAGERS_EDIT_MANAGER" : newPage ? "DIC_ADMIN_SETTINGS_ACCOUNT_MANAGERS_NEW_MANAGER" : "DIC_ADMIN_SETTINGS_ACCOUNT_MANAGERS_VIEW_MANAGER"} />} />

                </div>
render(){
const viewPage=this.props.history.location.pathname.includes(“/app/accountManagers/view/”)
const editPage=this.props.history.location.pathname.includes(“/app/accountManagers/edit/”)
const newPage=this.props.history.location.pathname.includes(“/app/accountManagers/new/”)
返回(
componentDidMount(){
const viewPage=this.props.history.location.pathname.includes(“/app/accountManagers/view/”)
const editPage=this.props.history.location.pathname.includes(“/app/accountManagers/edit/”)
const newPage=this.props.history.location.pathname.includes(“/app/accountManagers/new/”)
返回(
)
}

为什么不简单地使用路由而不是根据需要在索引页中更改标题的路由匹配位置。因此,我使用了此逻辑,因此此组件不会在上述路由之一上呈现?