Default component in "/" but being able to use different routes?

Hey Let's say I have an app to read books (example) in app router. I want it to render that app default in "/", when the user clicks in a book (inside the app component) a book will show up, and the route change to "/matilda". So how it should be done? I was thinking to wrap it and put it in a layout.tsx the issue is that I don't want everytime to render the book app, for example in "/about", but yes in "/matilda". I could have that app inside the route "/app".. and matilda exist in "/app/matilda", but it won't be default in the root "/" Any idea? thanks!
4 Replies
Kenzo
KenzoOP12mo ago
here people are recommending to use middleware and just redirect the user?
Kenzo
KenzoOP12mo ago
-------- is this a good solution in next 13?
No description
Kenzo
KenzoOP12mo ago
can't use window or useRouter().pathname in Next ----------- ok, i tried
const heads = headers();
const pathname = heads.get("next-url");
const heads = headers();
const pathname = heads.get("next-url");
but its not working properly neither so the main layout will ever render the component, and inside the component I need to know if we are in "/" or in a subroute of "/wiki/" how? Hope it works in ssg too
Want results from more Discord servers?
Add your server