Skip to content

Values not loading on a server side render using <StaticRouter> #51

@jordanrastrick

Description

@jordanrastrick

I'm having trouble getting use-query-params to correctly fetch query param values on a Server Side Render. We are using <StaticRouter> from react-router-dom, initialised as is standard with the known value of location from the request.

Looking at the source here it seems that the assumption is being made that on a SSR the query must be extracted from location.pathname rather than from location.search. However AFAICT <StaticRouter> puts the query string in location.search consistent with <BrowserRouter>.

It seems like it might make more sense just to test directly for the presence of location.search and only fallback to parsing pathname if the former is missing, rather than checking for window? (although I'm not sure if this approach would be compatible with other routing frameworks...)

I will in the meantime workaround this using rawQuery but it'd be nice for it to work out of the box to reduce complexity and allow us to phase out other query string related packages completely in favour of just using this.

Cheers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions