I am using Next.js and I want to know how to change the url on the same page without refresh it. I am using shallow=true but it still render to the next page.
This is my code:
<Tabs>
<Tab href='test/1' label='Sample Exam'/>
<Tab href='test/1/exam' label='Test Exam'/>
</Tabs>
<TabPanel value={tabvalue} index={0}>
<SampleComponent />
</TabPanel>
<TabPanel value={tabvalue} index={1}>
<TestComponent />
</TabPanel>
This is the logic but does not work
const [tabValue, setTabValue] = React.useState(0);
const router = useRouter();
const handleChange = (event: React.ChangeEvent<{}>, newValue: number) => {
setTabValue(newValue);
useEffect(() => {
router.replace('/test/1', '/test/1/exam', { shallow: true});
}, []);
};
I have already test router.push it does not work and windows replace state is a bad idea. The tabs will look like this.
Sample Exam | Test Exam
if you click sample exam it will show the Sample Details same with the Test but it must be on the same page.
Thanks.