Next.js Discord

Discord Forum

Different image in layout based on route?

Answered
Red-necked Grebe posted this in #help-forum
Open in Discord
Avatar
Red-necked GrebeOP
I have a layout for a login & signup page but I want different images based on the route you're on. Is there a way to do that with layouts? Or do I just have to copy-paste the actual html layout code to a login & signup page and change the image that way?
Answered by Red-necked Grebe
thanks, that worked nicely
View full answer

3 Replies

Avatar
Havana
You could determine it based on the pathname which you can get from importing „usePathname“ from „next/navigation“ and then using it like this:
const pathname = usePathname()
. Based on the pathname you could determine if the user is on the login or signup page and change the image accordingly
Avatar
Red-necked GrebeOP
thanks, that worked nicely
Answer
Avatar
Large garden bumble bee
Please mark the solution