'next js dynamic route redirect to home page on refresh
I have a dynamic route in my project and its not ssr.
When I refresh the page, it redirects to the home page, but in the other pages
the refresh works as intended.
I have actually added trailingSlash: true
to my next.config but it still doesn't works.
const redirectToLivePage = async () => {
const result = await dispatch(
getMeetingAction(meetingId, { shares_count: shares }),
);
if (result.ok) {
router.push(`/meetings/${meetingId}/shares_count=${shares}`);
}
};
here is the codes of my dynamic page.
const MeetingPage = () => {
useEffect(() => {
let interval;
if (data?.data.stream_status !== 'complete') {
interval = setInterval(() => {
dispatch(getMeetingAction(id, { shares_count: shares }));
}, 5000);
}
return () => {
clearInterval(interval);
};
}, [data]);
return (
<>
{data?.data?.stream_status === 'complete' ? (
<Player src={data?.data?.stream_hls_playlist || ''} />
) : (
<div
className={s.poster}
style={{ backgroundImage: `url(${poster})` }}
>
<div className="container">
<p>{BE_PATIENT}</p>
</div>
</div>
)}
<div className={cs('container', s.message)}>
<SendMessage id={data?.data?.id} />
</div>
</>
);
};
export default MeetingPage;
It happens on production, In local it works well.
Solution 1:[1]
Probably related to NextJS caveats, I had the same issue, you can read about it here
It should be fixed by:
export async function getServerSideProps(context) {
return {
props: {},
};
}
Also don't forget to restart the app.
Hope this help to someone else.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | masmerino |