我试图弄清楚如何使用 next.js 路由来使用路由指令填充侧边栏组件,以便在单击侧边栏选项时,主 div 会填充相关组件。
我可以找到显示侧栏菜单项的 CSS 的教程,但我找不到此任务的 next.js 路由说明。
到目前为止,我有一个侧边栏组件:
function Sidebar({}) {
// I also tried adding href inside the above {} but it didn't work
// const { me, loading } = useMe()
const { me, loading: meLoading } = useMe()
if (meLoading)
return (
<Center>
<Spinner />
</Center>
)
return (
<Flex as="section" minH="100vh" bg="bg-canvas" maxW="100%" p="0">
<Flex
// px={{ base: '4', sm: '6' }}
>
<Stack justify="space-between" spacing="1">
<Stack spacing={{ base: '5', sm: '6' }} shouldWrapChildren>
<InputGroup>
<InputLeftElement pointerEvents="none">
<Icon as={FiSearch} color="muted" boxSize="5" />
</InputLeftElement>
<Input placeholder="Search" />
</InputGroup>
<Stack spacing="1" >
<NavButton label="Home" fontWeight="normal"/>
<Link href={Library} passHref>
// I have tried several other versions of this without the passHref, using href="/Library" and a range of other things - but I cant find anything that works - or makes sense as way to put the content in the Container that currently displays lorem ipsum as below
<NavButton label="Library" aria-current="page" fontWeight="normal" />
</Link>
<NavButton label="Tasks" fontWeight="normal" />
</Stack>
</Stack>
然后我有另一个名为 Dashbase 的组件,它应该是显示所选侧边栏选项的相关组件的位置(而不是 lorem ipsum)。
const DashBase = () => {
const isDesktop = useBreakpointValue({ base: false, lg: true })
const router = useRouter()
return (
<Flex
as="section"
direction={{ base: 'column', lg: 'row' }}
height="100vh"
bg="white"
mb="100px"
overflowY="auto"
minW="100%"
px={0}
mx="0px"
// minW="120em"
// margin="auto"
>
{isDesktop ? <Sidebar /> : <Navbar />}
<Container py="8" flex="none">
<Text> lorem ipsum dolor sit amet, consectetur adipiscing lorem ipsum dolor sit amet, consectetur adipiscing
</Text>
</Container>
</Flex>
)
}
export default DashBase;
<Stack spacing={{ base: '5', sm: '6' }}>
<Stack spacing="1">
<NavButton label="Help" fontWeight="normal"/>
<NavButton label="Settings" fontWeight="normal"/>
</Stack>
<UserProfile
name={me.firstName + " " + me.lastName}
// image="h"
bio={me.bio}
/>
</Stack>
</Stack>
</Flex>
</Flex>
)
}