0

I've got a project setup in NextJS 13.4.7 and am wanting to use the src/ directory structure. I've got my app folder which has the following structure:

app/
  [lang]/
    page.tsx
    layout.tsx

This works fine when it's outside the src/ structure, but when I move everything into it the routes are not recognised anymore and instead I get a 404 showing up. Unless I go to /src in the browser - then the routes show up as expected.

I have a middleware file which does the localisation, should that be moved inside the src/ folder structure as well or kept in the route?

I have deleted the .next folder from the project before re-running npm run dev here as well, as others have suggested: Moving Pages folder in Next.js application to src folder

Cheers!

lewisnewson
  • 410
  • 6
  • 22
  • Please read and follow the [official documentation](https://nextjs.org/docs/app/building-your-application/configuring/src-directory) on this topic. – Fabio Nettis Jul 03 '23 at 11:40
  • Hey Fabio, I have done so but to no avail - hence my question on here. It's possible someone else may have encountered the same issue before. – lewisnewson Jul 03 '23 at 11:42
  • Based on your example, your folder structure should look like this: `/src/app/[locale]`. Could you confirm you are exactly following this pattern? – Fabio Nettis Jul 03 '23 at 11:44
  • That's correct, my project structure now looks like that only my route is `[lang]` instead of `[locale]`. It's worth noting here that moving my middleware.ts file (as described here: https://nextjs.org/docs/app/building-your-application/routing/internationalization) then triggers the routes to be loaded, but it then tried to look for a layout.tsx file outside the `[lang]` folder which is confusing as it doesn't perform like that when outside the `src/` structure – lewisnewson Jul 03 '23 at 11:49
  • You always need a root `layout.tsx` file. The root layout should also include the `` tag as it is the root of your application. The `middleware.ts` file should be contained in `src/`. – Fabio Nettis Jul 03 '23 at 11:52
  • Thanks for your input Fabio, looks like all I needed to do was move the middleware.ts file inside the src folder as well. The layout.tsx file isn't required in the root here as the middleware rewrites the base url to one that includes a locale - thus the layout.tsx inside the `[lang]` is sufficient enough as it acts as the root – lewisnewson Jul 03 '23 at 12:12

0 Answers0