Exploring the layout of an exported website in Next.js

Looking for a wizard in the world of Next.js to assist me with this query, or at least be straightforward and inform me if it is an impossible task.

We have a website that is compiled into static files. These files will be hosted on S3.

After running next export, everything builds correctly. However, I had hoped to access subpages directly without needing to add the .html extension. I mistakenly assumed that Next would build pages into directories and place an index.html file in each directory.

The development setup is quite simple. Each component has its directory, for example, "some-component." Within this directory, there is an index.js file exporting the named component from an adjacent file like "some-component.js."

Everything works when starting at the root of the site - I can navigate to /components/some-component without worrying about the extension.

Next has indeed created a directory called some-component, but the file inside it is still named some-component.html. Therefore, if you try to access that URL from your browser, it results in a 404 error.

Is there a way to make Next output index.html files into the directories so that browsing directly to the directory (try saying that after a drink) would work? Or am I pursuing the wrong path here?

I understand that there may be other solutions out there, especially for integrating with S3, but I thought it wouldn't hurt to ask about this specific approach.

Cheers!

Answer №1

If you are working with Next.js, there is a useful trailingSlash setting that can be implemented like this:

// next.config.js
module.exports = {
  trailingSlash: true,
}

When the trailingSlash setting is set to true, for example when using ./pages/products/shoes.jsx, a directory named after the .jsx file (shoes) is created. The .jsx file then becomes an index.html file inside that directory, resulting in a path like href="/products/shoes/". Your server will serve the corresponding index.html (or can be configured to do so) even if index.html is not specifically mentioned in the href.

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

Coordinating the retrieval of JavaScript files using both AJAX requests and the <script> tag

core.js: var core = { all:{}, load: function(jsUrl) { $.ajaxStup({async, false}); $.getScript(jsUrl); }, init: function () { $.getJSON('someurl', function(data) { for(key in th ...

Discovering the data from a JSON serialization in JavaScript

Within my PrintViewModel list, there is a sublist called Summary. I am working with ASP.NET MVC. @model CRC.Models.PrintViewModel; <label id="lblTotalMonthlyLoanDeduction"></label> I am serializing it using JSON. var obj = @Json.Se ...

Constructing an Http Post URL with form parameters using the Axios HTTP client

I need assistance in creating a postHTTP request with form parameters using axios on my node server. I have successfully implemented the Java code for constructing a URL, as shown below: JAVA CODE: HttpPost post = new HttpPost(UriBuilder.fromUri (getPro ...

What is the best way to transfer a C# object to the browser and convert it into a JavaScript JSON object?

I have a Product class. I currently have an instance of it that I need access to in both my Razor page and in my browser JavaScript. My solution was to render the Product into the page and then parse it using JSON.parse. Within Product.cshtml: @{ var ...

Top method for managing a past session in NextJS for online retail sites

Imagine I am managing an online store. The majority of APIs are hosted on a separate server. A customer adds items to their cart Logs in, or decides not to Exits the site They return at a later time. The session is activated from a cookie, pre-filling ...

Using the Amazon S3 PHP class to access storage without needing credentials

I am currently in the process of integrating Amazon S3 bucket service into our Project. I have opted to utilize a PHP class available at https://github.com/tpyo/amazon-s3-php-class. Specifically, I am utilizing the 'putObjectFile' method from th ...

How can you use JavaScript to iterate through every object using a for loop?

I'm trying to determine if a button is clickable based on certain requirements, but I can't seem to get the initial function to work. Within this object array, each object represents a button with specific requirements. For example, the "story" ...

Steps for displaying a download button on a video using JavaScript

I am working on a Django project and have a video.html file for displaying videos. The code I currently have is used to display the video, but I would like to change the appearance of the play button and add a download button similar to this https://i.sst ...

Enabling Cross-Origin Resource Sharing (CORS) for PUT requests in

When attempting to send a PUT request to my REST API endpoint, I encountered the following error message: Method PUT is not allowed by Access-Control-Allow-Methods in preflight response. I managed to enable CORS for POST requests using the solution provi ...

Retrieve all the items listed in the markdown file under specific headings

Below is an example of a markdown file: # Test ## First List * Hello World * Lorem Ipsum * Foo ## Second List - Item 1 ## Third List + Item A Part of Item A + Item B ## Not a List Blah blah blah ## Empty ## Another List Blah blah blah * ITEM # ...

Is there a way to dynamically alter the text color in a tag based on its value?

Utilizing ajax technology, I aim to dynamically populate a div tag with values from a table. I believe that implementing a loop is crucial in this scenario, but the challenge lies in executing it correctly. My current setup involves xampp for backend php ...

Determining the current month of the user when utilizing the v-calender

Struggling with my v-calendar plugin on a website, I need to determine the month and year that the user is currently viewing to implement some specific changes. How can I access this information as the user moves through the calendar? https://i.sstatic.ne ...

Animating with React JS using JSON data sources

Currently, my project involves using React/Redux to store animation data in JSON and display it on a React page. The challenge lies in implementing the animations correctly while utilizing setTimeout for pauses and setInterval for movement. The Animation ...

The function useSupabaseClient() does not return any value

I am currently in the process of following Antonio's tutorial on creating a Spotify clone (at 2:08:00), but I have encountered an issue. The function useSupabaseClient() is returning undefined, which results in this line <Auth supabaseClient={supab ...

Having trouble setting the function props type for its child in Typescript? Getting an error that says "Property 'children' does not exist on type TS2339"?

To provide context, my development environment includes React version 16.9.0 and Typescript version 3.5.3. To replicate the issue, you can install Create React App and create a Typescript project, then add this minimal example: import React from 'rea ...

Tips for automatically updating a Next.js page at midnight

I am facing an issue with my page refreshing at midnight. Currently, I have set the revalidation to 60 minutes, but this results in unnecessary refreshes throughout the day and sometimes causes delays. The page does not refresh correctly or exactly at midn ...

Managing iframe scrolling using the parent window's scrollbar

I am currently working on an iframe to be utilized across various domains. The functionality of this iframe involves displaying a data list that updates when the bottom of the scroll is reached. An issue I encountered is that the parent window, where the ...

I want to know how to keep additional inline whitespace while using the default JS/TS formatter in VS Code

Take this line, for example: var x = 5; var yyyyy = 10; var zzzzzz = 15; The VS Code Formatter removes the extra spaces between variable names and values. var x = 5; var yyyyy = 10; var zzzzzz = 15; Is there a way to configure it to keep the f ...

Ways to dismiss a Modal popup instantly without having to wait for an ajax response

I am currently facing an issue with sending email attachments through ajax. The process takes too long to send and close the email modal window. I am looking for a solution where the modal window closes immediately after clicking the send email button, all ...

Convert millimeters to inches with a unique AngularJS filter that activates on click

I am currently working on a UI that requires users to enter dimensions for width and height. Within the UI, there are 2 buttons available - one for 'mm' and the other for 'inches'. When either of these buttons is pressed, the active cl ...