-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How do you access the current URL in a component? #2019
Comments
@nwshane See #1708 (comment) I think this should do the job EDIT: Also #194 |
@Florian-R Thanks for your answer, Florian. The method
It seems like the Router is only available on the client side? What's the best way to get the |
I managed to solve this already but with a rather inelegant solution. On the client side, I use Here's the relevant code from
And here's my LocaleLink component:
Ideally, I would like to remove the dependency on React's context, as well as the need to check manually whether I'm on the server or client side to decide how to get the |
Actually, we already have the react context support for the router. We need to implement a public API for that. |
I think this question is already answered and we'll have a proper way to access the router with this: #2032 |
This is achievable with the |
I want to create a LocaleLink component that navigates the user to the current page, but in the specified locale. The locale is part of the URL, so clicking on the "Deutsch" link while on the
/en/posts/hurray-next-js
page will take you to/de/posts/hurray-next-js
.In order to implement this LocaleLink component, I need to give it access to the current path. What's the best practice for passing the current path to LocaleLink? I can use
window.location.pathname
on the client side, but is that the best practice? And how can I get the pathname on the server side?Thanks, and if this question doesn't belong here, let me know.
The text was updated successfully, but these errors were encountered: