Skip to content
Discussion options

You must be logged in to vote

Client-side you should use an effect, the component render is not only client-side (it runs server-side) that's why Remix hooks only gives you the pathname, the origin can be anything (Remix and RR doesn't handle that part).

I would return the origin from a loader

export async function loader({ request }: LoaderFunctionArgs) {
  let url = new URL(request.url)
  return json({ origin: url.origin, pathname: url.pathname })
}

Another option could be to use window.location.href in entry.client (this runs 100% client-side) and use a custom context to make it globally available for React, and since your components run server-side you will need the same context in entry.server where you can also …

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@nikolailehbrink
Comment options

Comment options

You must be logged in to vote
3 replies
@nikolailehbrink
Comment options

@sergiodxa
Comment options

Answer selected by nikolailehbrink
@nikolailehbrink
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants