0

We have:

pages/[providerSlug]/index.ts
pages/account/index.ts

When we visit /account (with no query), this code in [providerSlug]/index.ts gets hit:

export const getServerSideProps = async (context) => {
   console.dir(context)
}

outputs:
  ...
  query: { providerSlug: 'null' },
  resolvedUrl: '/null',
  params: { providerSlug: 'null' },

Two questions:

  1. Why is [providerSlug]/index.ts being hit? Shouldn't only account/index.ts be hit? I tried adding getServerSideProps to account/index.ts as well (it doesn't have it), made no difference.
  2. Where is resolvedUrl & query.providerSlug getting set? I cannot find how this is getting set but it must be in our code somewhere -- what gets hit before getServerSideProps that I should look at?

thanks.

1 Answer 1

2

Instead of

pages/[providerSlug]/index.ts
pages/account/index.ts

Set up

pages/[providerSlug].ts
pages/account.ts

/account should now correctly take precedence on /foo

If you ever need to capture /foo/bar you can setup

pages/[providerSlug]/[secondarySlug].ts

or if it's a full slug, you can put an optional catch all route : https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes

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

Comments

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.