After exporting static HTML, the links in Next.JS seem to become unresponsive

Exploring the world of NEXT.JS for the first time and encountering challenges with deploying a static site. In my component Nav.tsx, I have the following structure:

const Nav = () => {
    return (
        <nav className='nav p-3 border-bottom'>
            <Link href='/' passHref>
                <a className='pointer my-auto h2'>Blog </a>
            </Link>
            <Link href='/about' passHref>
                <a className='ms-5 pointer lead my-auto'>Who We Are</a>
            </Link>
            <Link href='/services' passHref>
                <a className='ms-5 pointer lead my-auto'>Services</a>
            </Link>
            <Link href='/contact' passHref>
                <a className='ms-5 pointer lead my-auto'>Contact</a>
            </Link>
        </nav>
    );
};
export default Nav;

During local server development, I can navigate using these links smoothly. However, after building and exporting using

next build && next export
, the navigation links no longer function as expected. The paths (/about, /services, /contact) are all present in the pages directory. Am I missing a key detail in Nav.tsx or is there a fundamental misunderstanding of how NEXT.JS operates? Any help would be greatly appreciated!

Answer №1

Latest Update: February 14, 2022

If you're facing a similar issue, consider adding {trailingSlash: true} in your next.config.js file. Refer to this helpful thread for more information.

Original Solution (Not recommended)

In my recent experience, I came across the same hurdle and figured out a different workaround. By reorganizing non-index pages like pages/search.js to be placed under pages/search/index.js, you can resolve this issue without resorting to tweaks like manipulating .htaccess.

Don't forget to adjust your relative imports accordingly so Next.js can still compile successfully. For example:

import styles from '../styles/Home.module.css';

should be changed to:

import styles from '../../styles/Home.module.css';

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

Problem with mobile device: I keep getting redirected to unknown routes when tapping on random areas

My project built with Next.js 13.4.19 is causing some strange issues after deployment. If you want to see the problem: Open on a mobile browser. Start tapping on areas where there are no links (like headers or paragraphs). You will be redirected to rand ...

Running a Blitz.js api handler triggers a Google Cloud Storage call failure with the message "error:0909006C:PEM routines:get_name:no start line"

When attempting to utilize @google-cloud/storage within a Blitz.js /api handler, I encounter the following error: error:0909006C:PEM routines:get_name:no start line at Sign.sign (internal/crypto/sig.js:110:29) at NodeCrypto.sign (C:\Users&bsol ...

Next.js does not transfer routing parameters

After developing an application in Next.js version 9.4.4, my folder structure looks like this: pages [id] index.js index.js Whenever I send a request to localhost:3000/something, it always redirects to the index page. However, when I try to log this inf ...

Express server encounters a 404 error while processing a POST request

Recently, I encountered an issue while trying to post data to my express server using a function that is triggered by clicking a button. Here's the code snippet of the function: const fetchData = async () => { const response = await fetch(&apos ...

Retrieving a targeted JSON element and adding it to a fresh object

Hello everyone, I have an object that resembles the following structure: [ { "app": 1, "scalable": true, "zoomable": true, "cropBoxResizable": true }, { "app" ...

Using Mongoose and MongoDB to reference a different schema without using the default ObjectId reference

I have two different schemas in my current project. var carSchema = new mongoose.Schema({ id: { type: Number, unique: true, required: true }, make: { type: String, required: true }, model: { ...

Comparing ngrx and redux for managing state in stateless components

Exploring ngrx/angular 8 for the first time, I'm curious to know if the angular approach of using an observable to bind a state value to the this context still allows a component to remain presentational and stateless. In the realm of angular/ngrx, c ...

Bookshelf.js has implemented a new feature where it automatically encrypts passwords with bcrypt every time data is updated

My User Model is var Bookshelf = require('../../db').bookshelf; var bcrypt = require('bcrypt'); var Promise = require('bluebird'); var Base = require('./../helpers/base'); // Custom user model var Custom_User_Mod ...

What criteria does Nextjs utilize to determine the appropriate router to use?

Having recently started using Next, I'm curious about how the routing works. If I were to create both pages and an app folder, how does Next determine which router to utilize? Is there a specific configuration setting or environment variable that dict ...

jQuery can be used to obtain the label for a checkbox with a particular value

Currently, I am facing an issue with retrieving the label for a checkbox using jQuery. Let me provide you with the relevant HTML code: <div class="checkbox"> <label><input type="checkbox" name="cb_type[]" value="sold" >Sold</label ...

Utilize a visual representation as the icon within an IconButton component in ChakraUI

Is there a way to incorporate a .png file into the IconButton in Chakra UI? I've tried setting icon="/image.png and src="/image.png, but it doesn't seem to work. How can I successfully pass an image as the icon for the IconButton compon ...

Addressing file routes within my personalized npm bundle

I am in the process of developing a custom npm package called packer and experimenting with a configuration similar to webpack, where users can install my CLI tool to build their packages. Here is an example of a package.json file for a test package using ...

What is the proper way to activate speech recognition on electron?

I have a chatbot application running on Electron, and I am in need of implementing speech-to-text functionality. I initially tried using window.SpeechRecognition and window.webkitSpeechRecognition, but it seems like Chrome does not support speech recogniti ...

Unique custom CSS and meta tag options for enhancing iPad/iPhone user experience

Currently, I am developing a web application that integrates Extjs components, PHP, and MySQL. My main goal is to ensure that my application looks correct on the iPad. Are there any specific CSS rules or meta tags that I should be implementing for optima ...

retrieving the configuration settings from my customized service

When attempting to access my custom service within its config property in order to inject an HTTP interceptor, I am encountering the following issue: angular .module("common.services") .factory("redirectService", [" ...

Can you explain the concept of a TransientTransactionError within Mongoose (or MongoDB)?

Two important files in my project are server.js and db.js. The db.js file is responsible for interacting with the database using Mongoose, while server.js calls functions from db.js: var mongoose = require('mongoose'); mongoose.connect('&ap ...

Send an ArrayList to jQuery Flot

Good day. Apologies for any language barriers as English is not my first language. I am a novice in [see tags] and I have a web application that gathers a date and a serial number to execute a SQL query. The query returns some data (measurement values an ...

The carousel's slides don't behave properly when swiping or using the slider controls (next/prev)

I have recently completed the construction of a carousel with swipe/touch functionality and control buttons for previous and next slides. However, I am facing an issue with the behavior of the carousel as it seems to be sliding by 2 or 3 instead of one at ...

Managing cookies with ReactJs: A guide to setting, storing, and updating cookies without deleting the existing ones

How can I create a cookie that stores input values when the user submits a form, and updates the cookie without removing previously saved data on subsequent submissions? export default function saveToCookie() { const [ name, setName ] = useState('&a ...

Tips for creating a JSON cross-domain call in PHP

Hello, I'm just starting to dive into JSON cross domain. I've encountered an issue that I need help with. I am trying to make a cross-domain call to PHP using JSON, but I keep encountering errors. Here is a snippet of the code that I'm worki ...