【发布时间】:2021-03-19 17:24:20
【问题描述】:
我是 javascript 新手并做出反应。我做了很多谷歌搜索没有解决方案。我试图在当前显示的三个页面/路线之一上隐藏一个按钮组件,但是当我尝试这样做时,它隐藏在所有页面/路线上。代码如下:
const routes = [
{
path: '/:bookId/details',
title: 'Book Details',
component: BookDetailsPage,
hideButton: true
},
{
path: '/:bookId',
title: 'Details',
component: BookPage,
exact: true,
hideButton: false
},
{
path: '/',
title: 'Book',
component: BookListPage,
hideButton: false
}
];
const Page = (): React.ReactElement => {
const isBookDetailsPage = routes[0].hideButton; //returns true
return (
<ContentMasterLayout
title="Book"
action={
<Box display="flex">
//this approach hides the button on all pages
{!isBookDetailsPage &&
<BookButton transactionId={match?.params.bookId} />}
</Box>
}
>
<LocalRouter routes={routes} />
</ContentMasterLayout>
);
};
如有任何帮助,我们将不胜感激。提前致谢
【问题讨论】:
标签: javascript reactjs react-router react-router-dom react-router-v4