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.
See #54646 (comment)
How
A new selector in calypso/state/selectors
to get the current route path & query as a string.