我们最近将我们的应用程序从单片RubyOnRails移植到React / Redux Framework。 我们在google的结果中遇到了react-router和google缓存页面的问题。在这种情况下,我们有一个SPA(单页面应用程序),它使用react-router(通过browserHistory)。这里的问题是:谷歌缓存页面是一个页面包装器,其中URL与SPA路由器中定义的URL不同。因此,在这种情况下,应用程序的路由属于未找到的页面的定义。而且谷歌的SPA页面的缓存结果,而是显示页面的内容,页面被重新加载到/搜索(包装路径)。
React Router Version:3.0.3 反应版本:15.4.2
以下是我们处理通用网址的方式:
<Route onEnter={hitTheServer}>
<Route path="*" component={Home} />
</Route>
hitTheServer定义:
const hitTheServer = (nextState, replace, cb) => { const url = `https://${config.server.public.host}${nextState.location.pathname}`; // Hit the server only on client side rendering. A hack to handle unimplemented pages if (typeof window !== 'undefined') { window.location = url; } else { cb(); } };
在这里,我们正在进行页面重新加载,因为有些链接仍未通过SPA实现,因此,在整页重新加载时,这些链接是通过nginx路由到各自的服务器(rails或节点)。