Use both fs and usePathname in a project.
Answered
Bahama Swallow posted this in #help-forum
Bahama SwallowOP
in next13 i am currently trying to write a program which intentionally interfaces with the filesystem, for instance when at /{path}, next opens the folder at the given route to display photos, however with the whole client/server thing i'm not entirely sure how to set it up.
i'd like to get the pathname from a client comp and then return it to a server comp which fetches the data in the given folder, however as i said, i'm not entirely sure how to set it up. as of now i have no real helpful code snippets to provide
any ideas ? :)
i'd like to get the pathname from a client comp and then return it to a server comp which fetches the data in the given folder, however as i said, i'm not entirely sure how to set it up. as of now i have no real helpful code snippets to provide
any ideas ? :)
Answered by joulev
use the params prop in the page component to construct the pathname in the server where you can access fs https://nextjs.org/docs/app/api-reference/file-conventions/page#params-optional
6 Replies
Bahama SwallowOP
lemme expand, if I have both
<GetPath />
<GetFiles />
in the same page comp it works, but i'd like to be able to get the pathname and use it like this
<GetFiles dir={GetPath()} >
<GetPath />
<GetFiles />
in the same page comp it works, but i'd like to be able to get the pathname and use it like this
<GetFiles dir={GetPath()} >
but it always throws an error when doing anything with GetPath()
Bahama SwallowOP

@Bahama Swallow in next13 i am currently trying to write a program which intentionally interfaces with the filesystem, for instance when at /{path}, next opens the folder at the given route to display photos, however with the whole client/server thing i'm not entirely sure how to set it up.
i'd like to get the pathname from a client comp and then return it to a server comp which fetches the data in the given folder, however as i said, i'm not entirely sure how to set it up. as of now i have no real helpful code snippets to provide
any ideas ? :)
use the params prop in the page component to construct the pathname in the server where you can access fs https://nextjs.org/docs/app/api-reference/file-conventions/page#params-optional
Answer
Bahama SwallowOP
oh beautiful
ty :3