The Next.js React application fails to load the updated page when clicking on a Link

I am currently working with Next.js version 14, utilizing the App router and the Link component from Next.js's next/link. In my file structure, within folder app/a, there are:

  • page.tsx which fetches data from an API and passes it to the <Table/> component...
  • Table.tsx, a client-side component with "use client". The table component is entirely client side due to my use of Mantine's tables.

On localhost:3000/a, I have a table that displays data fetched from an API. One of the columns in this table contains links (Link) with their hrefs set to localhost:3000/a?param=x. Clicking on these links should filter that column in the same table. However, when clicking the link, the URL in the browser's address bar updates correctly but the page does not reflect the change. Strangely, refreshing the page with the new URL shows the updated and expected table content. Opening the link in a new tab also displays the correct data.

Upon inspecting my VSCode console, I noticed that the API is successfully being called with the parameter when the links are clicked. Interestingly, when a link is clicked, GET /a?param=x is not logged in the console. But upon refreshing the page (now containing the link's URL), GET /a?param=x is indeed logged, and the correct data is displayed.

This issue only seems to occur for links within /a leading to /a?param=x, and not when navigating from /a to /b.

Answer №1

After conducting some research, I discovered that passing a key from my server component (Page) to client component (Table) -- using key={query_param} -- resolved the issue. It seems like the terms "partial rendering" and "soft navigation" are relevant for Next.js? Learn more at https://nextjs.org/docs/app/building-your-application/routing/linking-and-navigating#4-partial-rendering

For those not specifically working with Next.js: Check out this resource on when Component does not remount when route parameters change

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a concise wrapper for the Node.js 'request' module with optional parameters - how can this be streamlined?

I am currently in the process of developing a wrapper for node-request: var RequestWrapper = function(client, method, type, uuid, body, callback) { callback = callback || body || uuid // I want to improve this section for better readability ...

A guide on how to modify a CSS property to set the display to none upon clicking a radio button

Currently, I am attempting to display two input boxes in a table when I select specific radio buttons and hide them if I choose another option. The code I have does work but has a minor issue, function disappear() { document.getElementsByClassName("ta ...

Tips for transmitting a batch of resources with Restangular?

Suppose I need to make a DELETE request to delete multiple products from the resource /products. The complete request should be sent to this URI: /products/ids=1&ids=2&ids=3 What is the method to send a request like this using Restangular? The c ...

Running the test suite in another tab is causing it to fail

I am experiencing an unusual issue in my protractor UI test. During one of the tests, I need to click on a link that opens in a new tab. The test passes when run individually, but fails when run as part of the test suite. I would appreciate it if you coul ...

Tips for determining if a mobile web browser is active on a mobile device's foreground or background

I'm currently developing an angularjs html5 application. Just a quick question - is it possible to utilize pause/resume events in a mobile web application? Alternatively, you can help me by answering my question about how to check if the browser wind ...

Guide to dynamically insert rows in HTML using Vue.js based on the selected option

This is the initial row. Depending on the selection made here, different rows will be displayed <div class="row"> <div class="col-md-4"> <div class="form-group label-floating"> <label class="control-label">Case Type< ...

Locate within an HTML table (inside a specific td child tag) and conceal the row

I am trying to search for content within the H3 tag only, not the TD tag. If a result is found in the table, I want the corresponding TR to be hidden. -H3 is a child tag under TD. For example: <tr> <td> <h3>Example</h3> & ...

Issue with Angular Promise ($q) functionality being non-operational

I am currently experimenting with integrating Angular and SignalR in a demo application. I have attempted to implement promises using the $q service, but for some reason my code is not functioning as expected. SERVICE var boardConsole = $.connection.buil ...

Monitoring changes to localstorage in AngularJS

How can I monitor changes to localStorage using $watch? I have created a factory to simplify setting and getting values .factory('$localstorage', ['$window', function($window) { return { set: function(key, value) { ...

Elastic_Frame | "Error: Unable to process action as property 'toLowerCase' is not defined"

Attempting to create a personal and project portfolio using Vu Khanh Truong's "elastic_grid" jQuery plugin for the actual portfolio. You can access it here. However, encountering some issues on my page: 1) The header for the portfolio section disappe ...

Console.log is displaying array as [object Object] when utilizing Typescript

When working with an object in typescript called "obj," I encountered a strange behavior. Initially, when I ran the console.log(obj); command, the output in the terminal console was displayed as [object Object]. However, after wrapping it in JSON.stringify ...

The functionality of Angular.js ajax and apply is experiencing technical difficulties

As I venture into the world of angular.js, I am facing a challenge with displaying the correct content on my website. The pages' content is fetched via AJAX (currently from static data, but eventually from a database). When I place a block with the ng ...

Transform the Material UI grid orientation to horizontal row for content display

I'm just starting out with material UI and I've put together a grid that includes two components - an autocomplete and a button. Right now, they're stacked on top of each other, but I want to align them side by side in a row. Here's the ...

Generate Address from Latitude and Longitude

For my project, I am trying to convert latitude and longitude coordinates into an address. While the Google Maps API is a potential solution, it requires an XML Response which complicates the process. I came across this helpful thread on Stack Overflow d ...

Getting inaccurate results by entering numbers

const [shipping, setShipping] = useState({ overseas: '3' }) const handleChange = (e) => { setShipping({ overseas: e.target.value }) //can change to 8 or 3 } const selection = shipping.overseas console.log(sel ...

Tips for setting up a jQuery auto-suggest feature that fetches both the value and ID

Looking for a solution similar to an auto-complete feature, where a user can select from options already in a database or add new entries if not found. The goal is to retrieve the ID, send it to PHP, and check if it already exists. If not, a new entry shou ...

Trouble With Binding Input Field Inside Kendo Grid Using jQuery .on() Method

Lately, I have been focusing on a screen that incorporates a Grid (Kendo).... Within the Grid, there is a template that includes a straightforward button: <input type="button" class="iqs-review-btn btn btn-primary" value="REVIEW" /> I am attempting ...

How can the data from a factory be utilized within the same controller but in a separate file in an AngularJS application?

When trying to route from home.html to profile.html, there seems to be an issue with the execution of the profile.js script. I have data in script.js that is written in a factory. When the profile button is clicked, the page routes to profile.html, but the ...

What is the best way to retrieve all dates that are older than 30 days using JavaScript?

I have the following code snippet as a reference and I'm attempting to retrieve a list of dates from 30 days before. What do I need to change? Date.prototype.addDays = function(days) { var newDate = new Date(this.valueOf()) newDate.s ...

Adjust the div's height to 0

I need to dynamically set the height of a div element with a height of 34px to 0px. However, this div does not have a specific class or ID, so I can't use traditional DOM manipulation methods like .getElementById(), .getElementByClassName, or .getElem ...