Skip to content

State: Selector to get current route path and query #57109

Open

Description

What

A new state selector to get the current route path & query as a string e.g. test/url?foo=bar

Why

There are a few occasions in the repo where we need the relative URL with the search string for processing e.g. window.location.pathname + window.location.search. For example, in the signup flow: https://github.com/Automattic/wp-calypso/blob/trunk/client/signup/steps/user/index.jsx#L218

It would be great to have a state selector that utilises the already defined get-current-route and get-current-query-arguments in calypso/state/selectors to create an abstraction that combines the two.

Motivation:

My preference would be to create a new selector, createCurrentRouteURL, that constructs the entire /path?query string, and use that.

Imagine rendering the React component in an Express.js server, producing a static HTML response. There, you know the request URL: it's in the HTTP request and in the server's Request object. And you can use it to render the right signupUrl link. There's no window and no window.location though. The route information is available from a different source. Here, the Redux selector (or any other abstraction mechanism, e.g., some custom useCurrentRoute() hook) provides a unified way how to read the current route.

Originally posted by @jsnajdr in #54646 (comment)

See #54646 (comment)

How

A new selector in calypso/state/selectors to get the current route path & query as a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions