Replies: 3 comments 12 replies
-
Stumbled upon the same use case. Did you find any solution? We want to convert a project to next's app router, however there are urls with the same structure that map to different views/layouts. To give an example, here are some dynamic urls that are all under
Those that are of type category have a different presentantion than the 2 last ones. With pages router, depending on the response of the CMS, the appropriate components were returned (using conditions). We would like to avoid that with app router for better performance and cleaner code. We thought of creating different routes (e.g. |
Beta Was this translation helpful? Give feedback.
-
I'm dealing with the same problem trying to render different views for the same segment, any news ? |
Beta Was this translation helpful? Give feedback.
-
Hi there @cpotey , I've come for exactly the same reason so glad it's just not me that's had this issue. We use a CMS, and the pathname could be anything, so like you, I am checking for a page type in the response to load in the correct "Page component" if I can call it that, whilst in a catch all segment, so thanks for the idea for dyanmic import solution for now. The main issue i'm having now is we have a ResourceListPage type which needs server side pagination/sorting/filtering, and because of this it now makes all the possible routes miss SSG :( I wonder if you've had a similar issue for this and how you might have worked around it? Thanks, |
Beta Was this translation helpful? Give feedback.
-
Summary
Hi there!
I've got a django backend that we're trying to use headlessly now, but it currently means that I don't know the route (within Next) prior to calling the API - so can't split the code out like the docs assume.
If I call the API to get any page's data (using the slug) i.e.
apiendpoint.com/with-path/about-the-company
- it will return data in that response about what component/template/layout (or ideally, Next.js route folder) we will want to use{ pageType: "AboutPage", ...}
Currently this URL to view this page would be
mysite.com/about-the-company
- but we have tonnes of sub-directories, and every single page with completely different page types is currently only accessible to call on this onewith-path
endpoint.What's the best way to handle this situation within Next (App router ideally), as
apiendpoint.com/with-path/whatever-the-URL-is
will need to be called on every single page to return the data from the backend, and somehow make sure code-splitting will still be achieved?Is it just a case of having at the very top level of the /app having a
[slug].tsx
file, and then inside that a huge list of ifs passing through the API data for every component to should render that page, based on the API response?The alternative is we to do a load of 301 redirects (which feels risky?), and make each page template a different API endpoint - so that each route is its own thing
apiendpoint.com/about/about-the-company
,apiendpoint.com/blog/article-two
etc - which would match up far more with how Next.js expects things currently, as each "pageType" would be a separate route in Next.jsHope that makes sense! Thanks in advance
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions