I have a question about react-router and google cached pages in the results of google. In this case we have a SPA, which uses react-router (via browserHistory), the problem here is that: google cached page is a page wrapper, where the URL-a differs by the URL defined in the router of the SPA, in this case the routing of the application falls to the definition of a page not found.
(example )
and the cached result of SPA page by google, instead showing the content of the page is displayed component PageNotFoundApp (routing for page not found *).
Do you have any idea, what could be done about the resolving of the described problem?
2
Answers
An option would be to intercept the routing logic by using the
onEnter
eventAfter this, for the catch-all the route definition you can use something like this:
Please note that using of the injected
replace
function would actually navigate the browser to the path provided as a second parameter. I have not tested this in the case with google cache and it might be a wrong implementation.As an option you could pass a valid state as the first parameter of this function.
A solution to this problem might be bypass to loading of SPA if domain name is different. And it have a sense only when pages have fallback HTML version used when JavaScript disabled (see: https://web.dev/without-javascript/).
For example, HTML pages of SPA have to a base href
And
index.js
might be like thisAs a result, the search engines will index single page application, but if open the pages from the google cache, the fallback HTML pages will be shown.