When using SSG, how do I get the path of the current page being rendered from within getStaticProps?
Answered
Masai Lion posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Masai LionOP
I'm struggling to find a way to get the current path being rendered. I don't need the hostname, I just need the relative path.
Answered by joulev
Inside getStaticProps then:
* dynamic params are available in the context: https://nextjs.org/docs/pages/api-reference/functions/get-static-props#context-parameter
* other parts of the pathname can be hardcoded
* dynamic params are available in the context: https://nextjs.org/docs/pages/api-reference/functions/get-static-props#context-parameter
* other parts of the pathname can be hardcoded
4 Replies
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/f386ac21405ce3442e0f3598223e1cb3.webp?size=256)
joulev
use [
router.pathname
](https://nextjs.org/docs/pages/api-reference/functions/use-router#router-object)![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Masai LionOP
How do you get access to
router
from getStaticProps
?![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/f386ac21405ce3442e0f3598223e1cb3.webp?size=256)
joulev
Inside getStaticProps then:
* dynamic params are available in the context: https://nextjs.org/docs/pages/api-reference/functions/get-static-props#context-parameter
* other parts of the pathname can be hardcoded
* dynamic params are available in the context: https://nextjs.org/docs/pages/api-reference/functions/get-static-props#context-parameter
* other parts of the pathname can be hardcoded
Answer
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Masai LionOP
gotcha. After struggling to find another solution, I ended up hardcoding the known parts and using the params as you suggest. Thanks for clarifying that my eventual solution is correct, I appreciate you taking the time to help me out.