I'm encountering a 404 error on Next.js localhost:3000

Embarking on a fresh project in Next.js, my folder structure looks like this:

https://i.stack.imgur.com/HhiJo.png

However, upon navigating to localhost:3000, I am greeted with a 404 error screen. It seems there is an issue with the routing, but unfortunately, I have been unable to find any helpful information about it online.

Answer №1

Your file organization seems to be in disarray. Avoid placing the pages folder within the app directory.

Considering the filenames you're using, it appears you're working with the pages router. Try moving the pages folder up one level for better structure.

Refer to https://nextjs.org/docs#app-router-vs-pages-router for guidance on making the right choice.

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

Separate configurations for Webpack (Client and Server) to run an Express app without serving HTML files

I am currently developing an application with a Node Backend and I am trying to bundle it with Webpack. Initially, I had a single Webpack configuration with target: node. However, I encountered issues compiling Websockets into the frontend bundle unless I ...

Retrieving results from PostgreSQL database using pagination technique

When I'm pagination querying my data from a PostgreSQL database, each request involves fetching the data in this manner: let lastNArticles: Article[] = await Article.findAll({ limit: +req.body.count * +req.body.page, or ...

Enhance the functionality of 'takeWhile' by incorporating a limit parameter, similar to how 'take' operates

I am attempting to retrieve all pages until either there are no more pages or a certain limit (let's say 10 pages) is reached. If I follow this approach: obs.pipe(expand((page) => { return service.call(page).nextPage; }), take(10), takeWhil ...

When attempting to pre-render a Next.js page using getStaticProps(), an error occurs stating that the image is missing the required "src" attribute when using next/image

After reading the documentation for nextjs, I learned that the getStaticProps function should pre-render data that I need before a user visits my site. My goal is to fetch images and load them onto cards. In my index.js file: export async function getSta ...

There was a TypeScript error found at line 313, character 9 in the file @mui/material/styles/experimental_extendTheme.d

Encountering Typescript error while using Material UI component for date range picker Link - https://mui.com/x/react-date-pickers/date-range-picker/ Snippet of the code import * as React from 'react'; import { Dayjs } from 'dayjs'; im ...

Steps for confirming a property setting on an interface

I am working with the following interface export interface Command { id: CommandId; disabled: boolean; } My goal is to verify that the 'disabled' property has been changed. Here are my attempts: 1) Creating an object and checking if t ...

[LostAPIPathError]: Unable to locate the specified file [...nextauth].{js,ts} in the directory /pages/api/auth. Please verify the filename is accurate. However, the file exists

Having trouble finding a solution through browsing. I keep encountering this error message, even though everything was working fine when I initially created the app. However, now I am unable to authenticate on the deployed app or on different machines. The ...

Maximizing the potential of NestJS apps with Docker

I am working on a NestJS project that consists of multiple apps structured as follows: my-project: -- apps; --- app-one ---- src ---- tsconfig.app.json --- app-two ---- src ---- tsconfig.app.json -- libs -- package.json -- etc... Within this project, I ha ...

Next JS build throwing error: 'TypeError: r is not a function'

Encountered an error while building my app in NextJS 14.1.0. Below is the error that occurred during the build process: Generating static pages (0/15) [= ]TypeError: r is not a function at 20936 (D:\Projects\MyNextJSProject\.next&bsol ...

The console is displaying an undefined error for _co.photo, but the code is functioning properly without any issues

I am facing an issue with an Angular component. When I create my component with a selector, it functions as expected: it executes the httpget and renders a photo with a title. However, I am receiving two errors in the console: ERROR TypeError: "_co.photo ...

Modify the empty message for the PrimeNG multiselect component

Is there a way to customize the message 'no results found' in p-multiselect on Angular? I have successfully changed the default label, but I am struggling to find a solution to override the empty message. Here is my code snippet: <p-multiSel ...

Trying out the Testing Library feature with Emotion's 'css' function

Greetings, I have a couple of queries regarding Next.js, testing-library/react, and emotion. Before diving into the questions, let me share some code below: // Component import { css, Theme } from '@emotion/react'; function Foo() { return < ...

Sharing the current state with unspecified child elements

As someone new to React, I'm having trouble figuring out how to pass hover state down through components. I'm working with Next.js and styled-jsx. Back in the day with plain CSS, it was easy to change the text color of an element when its parent ...

Tips for handling promises in Next.js while using a forEach loop

I'm encountering an issue with ensuring that the foreach data is resolved before passing it to DrawChart(); After passing it to DrawChart(), the applicationName is consistently undefined. Is there a way I could prevent it from being undefined? useEff ...

What are the steps for integrating Socket.IO into NUXT 3?

I am in search of a solution to integrate Socket.IO with my Nuxt 3 application. My requirement is for the Nuxt app and the Socket.IO server to operate on the same port, and for the Socket.IO server to automatically initiate as soon as the Nuxt app is ready ...

Implementing Typescript for React Navigation: Configuring navigationOptions effectively

Within a React Native app utilizing React Navigation, I am working on a screen component where I aim to set the title based on given parameters using the navigationOptions property like so: static navigationOptions = ({navigation}) => ({ title: nav ...

NextJS - Error: Invalid JSON format, starting with a "<" symbol at position 0

After following a tutorial on NextJS, I attempted to make some modifications. My goal was to include the data.json file on the page. However, I kept encountering the error message "Unexpected token < in JSON at position 0." I understand that I need to ...

Utilize [slug] as the primary index in the following section as well

I'm currently delving into Next.js for a project, and I'm attempting to manage all the routes using just one file. Specifically, utilizing [slug].tsx instead of index.tsx. I gave it a shot but unfortunately it didn't work out as expected. An ...

using spread operator to extract properties from API response objects

Currently undergoing a React/Next course, we recently had to retrieve data from an API that returns a list of objects containing information to populate the page. This task was accomplished using Next's getStaticProps method, passing the data to the ...

Utilizing Next.js commerce and React with the useRouter hook in a functional component to create a dynamic header that

Currently experimenting with the Next.JS commerce framework and facing an issue related to setting dynamic Accept-Language headers in my graphql API request for correct translations. All routing is functioning as expected, and I am successfully receiving ...