如何在重定向到另一个组件时避免卸载组件? 这是我的代码 在应用程序组件中呈现
<SideMenu isOpen={appMenuShown} menu={<Menu />} onChange={appShowMenu}>
<Page exactly pattern="/" component={HomePage} />
<Page pattern="/todos" component={TodosPage} />
<Match
pattern="/"
render={({ location: { pathname } }) => {
const urls = ['/', '/todos'];
if (urls.indexOf(pathname) !== -1) return null;
return <Redirect to="/" />;
}}
/>
</SideMenu>
页面组件
const Page = (
{
component: Component,
exactly,
intl,
pattern,
}: PageProps,
) => (
<Match
exactly={exactly}
pattern={pattern}
render={renderProps => (
<Box
// We need flex and backgroundColor to cover SideMenu.
backgroundColor="white"
flex={1}
>
{titles[pattern] &&
<Header title={intl.formatMessage(titles[pattern])} />}
<Box flex={1}>
<Alert />
<Component {...renderProps} />
</Box>
</Box>
)}
/>
);
当我转到todos页面时,将调用主页组件的卸载。为什么?我怎么能避免呢?请帮帮我