Next.js Discord

Discord Forum

Getting current page from layout

Answered
Persian posted this in #help-forum
Open in Discord
PersianOP
Is there is any way to get the current page loaded in the children of a layout.tsx file?
Answered by ItetsuLaTable
The data must be store in database or somewhere else. It will allow you to fetch it from admin side
View full answer

13 Replies

PersianOP
Please ping when reply
Hello @Persian I'm not sure to understand well what you want to do
@ItetsuLaTable Hello <@589989048005689366> I'm not sure to understand well what you want to do
PersianOP
So i have different page that loads from the layout

i want the admin to choose permissions for certain pages to user to get access to, so in the layout i need to know which page is currently opened from the client side.. so i can choose weather to load the page or return to him that he's not authorized
@Persian sorry for time.

As long as Layout is the parent you dont know the children.
If you want to do something like this you have to store data on each page load
PersianOP
ok i will do that
The data must be store in database or somewhere else. It will allow you to fetch it from admin side
Answer
PersianOP
thanks
You can try to add real time to this to always have the current data
Moreover you can add a middleware to block some pages with permissions
And on admin side you will only able to edit permission
PersianOP
Yea i got the idea! thanks ❤️
Welcome! Good luck :hatblush:
I let you mark the thread as resolved