Reputation: 130
I have some folders ( auth, panel, ... ) and in the panel folder, I have some other folders like exam, article, project, ...)
I want to perform some code or function in all of the panel folder routes
for example, I'm writing a function it performs when the browser in panel/... routes
generally, I want to perform this function for all of the sub-routes of the panel folder(route)
I tried to locate my code in the inext.js of the panel folder and I thought it would work, but it didn't and it didn't run in all folders or paths under the panel folder
Upvotes: 3
Views: 345
Reputation: 240
You could take the router prop in _app.tsx
(app component which initializes your pages).
export default function MyApp({Component, pageProps, router}) {
if(router.route.startsWith('/panel')) {
/* insert your code here */
}
}
Upvotes: 3