Skip to content

Commit

Permalink
router.push
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoSoaress committed Apr 2, 2024
1 parent bf078e0 commit eff2208
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/pages/blog/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ const fetchContent = async (slug: string, isPreview: boolean) => {

const Page = () => {
const router = useRouter()

const { slug, secret } = router.query as { slug: any; secret: string }
console.log('slug & secret', slug, secret)
const [blogPost, setBlogPost] = useState<BlogPostEntry | null>(null)

useEffect(() => {
if (slug) {
router.push('/blog/[slug]', `/blog/${slug}`)

fetchContent(slug, !!secret).then((content) => {
setBlogPost(content)
})
}
}, [secret, slug])
}, [router, secret, slug])

return blogPost ? <BlogPost blogPost={blogPost} isPreview={!!secret} /> : <div>Loading...</div>
}
Expand Down

0 comments on commit eff2208

Please sign in to comment.