cassidoo / next-netlify-blog-starter

A lightweight markdown blog starter built with Next.js 12+ and Netlify
https://next-netlify-blog-starter.netlify.app/
Other
200 stars 55 forks source link

Full page refresh when clicking blog posts. #3

Open tr1s opened 4 years ago

tr1s commented 4 years ago

Hi!

I just went through your blog post on Netlify and was going to compare what I had just learned on Next's learn-starter blog to see what you both did differently for my own curiosities (still processing).

I noticed though when I clicked a blog post (from post list on the index page) I would get a full-page refresh when going to the blog post. I couldn't see what I did wrong so I came here to clone this repo and I got the same behaviour.

I preserved my logs and this is what I get:

CleanShot 2020-05-14 at 22 45 43@2x

But the post will still show up, but first it get's an error and refreshes.

Do you not get this behaviour? Not quite sure what's up 🤷🏽‍♂️

matiasleidemer commented 4 years ago

Hey, the issue happens because the <Link /> in the PostLink component should point to a dynamic route.

You can find more info about it in the docs.

Here's a working version:

<Link href="/posts/[postname]" as={`/posts/${post.slug}`}>
  <a>{post.frontmatter.title}</a>
</Link>
tr1s commented 4 years ago

Ah good call, missing the as attribute! Ty