question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Link component reloads the whole page in the new version(9)

See original GitHub issue

Bug report

Describe the bug

The Link component reloads the whole page after migrating to NextJS 9, and using the new dynamic routing APIs.

This is how i used the Link component before

<Link
  href={{
    pathname: "/news",
    query: { id: props.id }
  }}
  prefetch
>
    <a className={classes.link}>{props.title}</a>
</Link>

and this is after migration:

<Link href={`/news/${props.id}`}>
  <a className={classes.link}>{props.title}</a>
</Link>

and this the page folder:

pages
  news
    [id].js

this is the content of [id].js

import React from "react";
import SingleNews from "../../components/SingleNews";

const News = ({ id }) => {
  return <SingleNews id={id} />;
};

News.getInitialProps = async ({ query }) => {
  return { id: query.id };
};

export default News;

Expected behavior

For the Links to transition smoothly to other pages

System information

  • OS: Kubuntu
  • Browser: chrome
  • Version of Next.js: 9

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
delbaoliveiracommented, Jul 24, 2019

Hi @yassinebridi, this is not a bug. href in <Link> refers to the path inside your ./pages directory -https://github.com/zeit/next.js#dynamic-routing

Try this

<Link href="/news/[id]" as={`/news/${props.id}`}>
  <a className={classes.link}>{props.title}</a>
</Link>
1reaction
yassinebridicommented, Jul 24, 2019

thanks @delbaoliveira, that worked perfectly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IE 9 - Link (React Router) - Link click reload entire page
I've 16.8.4 version of React, 4.3.1 version for (React Router & React Router Dom) and 4.0.1 version of Redux. The actual result is...
Read more >
Angular: Reload/Refresh a Component or Entire ...
An Angular tutorial on how to reload/refresh a single component or the entire application and reuse the logic across multiple components.
Read more >
Nextjs causing hard refresh when i click in the Link #9382
I have an app react using CRA, and I am trying to turn it into an SSR app using next. So, since there...
Read more >
Force reload Next.js pages two ways! - YouTube
In this video I show you how to Force reload Next.js pages using the useRouter hook or in places that you ...
Read more >
Using React Router to avoid Page Reload | Django ... - YouTube
here is the github link for code:https://github.com/sauravsharmaz/My-Cart-Django-ReactVideo By - saurav.sharma.zz45@gmail.com Saurav ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found