7

I have the following url:

/job/engineer_123456/edit/abcde

Now when I run my local server: npm run dev ("next src/") then when i go to that link it works. However when I deploy my project (to firebase) then I get a 404 from that url.

I have a feeling there is a clash in the routing as my NextJS page directory structure looks like this /job is under pages):

enter image description here

Could it be that on production for some reason, when I go to that link, i am going to /job/[job].js instead of /job/[job]/edit/[editId].js

I am really confused why production shows a 404 page but locally it works.

1
  • huh? what has that got to do with this? Commented Nov 27, 2020 at 9:28

1 Answer 1

6

According to the documentation:

Predefined routes take precedence over dynamic routes, and dynamic routes over catch all routes. Take a look at the following examples:

pages/post/create.js - Will match /post/create

pages/post/[pid].js - Will match /post/1, /post/abc, etc. But not /post/create

pages/post/[...slug].js - Will match /post/1/2, /post/a/b/c, etc. But not /post/create, /post/abc

*Pages that are statically optimized by Automatic Static Optimization will be hydrated without their route parameters provided, i.e query will be an empty object ({}).

After hydration, Next.js will trigger an update to your application to provide the route parameters in the query object.*

So, you need to have something like:

pages - folder
    job - folder
        [...slug] - folder
            - index.js
            edit - folder
                - index.js

the slug folder will act as a "template" for all /job/[slug] routes which will have an index.js and also an edit page

Sign up to request clarification or add additional context in comments.

2 Comments

The results then in Error: Catch-all must be the last part of the URL.
Sorry, as a matter of fact, since you need the editID, you should have [...slug.js] inside your edit folder! That would catch all IDs, and index.js would be, ideally, the index page with all the objects

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.