单页应用SPA的缓存问题:F5对单页应用的影响

单页应用在使用router进行跳转之后,比如从index跳转到其他页面,在跳转之后的页面进行F5刷新,就会渲染出错:
clipboard.png
react找不到这个节点了

阅读 5k
2 个回答

Talk is cheap, show the code.

我的router是这样写的, 主要使用了react-router,页面的跳转用的是<Link to=""></Link>


import React from "react";
import {Router, Route, IndexRedirect} from "react-router";
import {TreeRoutes, PlainRoutes} from "./routes";
import StudentList from "../containers/Homepage/StudentList";

const loadModule = (callback) => (componentModule) => {
    callback(null, componentModule.default);
};

export default ({history}) => {
    return <Router history={history}>
        <Route path={TreeRoutes.index}>
            <IndexRedirect to={PlainRoutes.video_monitor.index}/>
            <Route path={TreeRoutes.video_monitor.index}
                   getComponent={(location, callback) => {
                       const renderRoute = loadModule(callback);
                       System.import('containers/App')
                           .then((component) => {
                               renderRoute(component)
                           })
                   }}>
                   ...
            </Route>
          </Route>
    </Router>
   
有什么问题么,谢谢!
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题