Next.js Discord

Discord Forum

Getting current page from layout

Answered
American Shorthair posted this in #help-forum
Open in Discord
American ShorthairOP
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

American ShorthairOP
Please ping when reply
Hello @American Shorthair 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
American ShorthairOP
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
@American Shorthair 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
American ShorthairOP
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
American ShorthairOP
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
American ShorthairOP
Yea i got the idea! thanks ❤️
Welcome! Good luck :hatblush:
I let you mark the thread as resolved