Giter Club home page Giter Club logo

goodluckalien / react-keepalive-router Goto Github PK

View Code? Open in Web Editor NEW
658.0 658.0 57.0 11.41 MB

The react cache component developed based on react 16.8 +, react router 4 + can be used to cache page components, similar to Vue keepalive package Vue router effect function.(基于react 16.8+ ,react-router 4+ 开发的react缓存组件,可以用于缓存页面组件,类似vue的keepalive包裹vue-router的效果功能)。

JavaScript 73.35% HTML 1.84% SCSS 10.30% TypeScript 14.51%

react-keepalive-router's Introduction

react-keepalive-router's People

Contributors

goodgoodstudy123 avatar goodluckalien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-keepalive-router's Issues

用react 18的import ReactDOM from 'react-dom/client' ReactDOM.createRoot 会报错,请问有解决方案?

index.js:905 Uncaught TypeError: Cannot read properties of undefined (reading 'state')
at CacheRoute.UNSAFE_componentWillReceiveProps (index.js:905:1)
at callComponentWillReceiveProps (react-dom.development.js:13607:16)
at updateClassInstance (react-dom.development.js:13844:9)
at updateClassComponent (react-dom.development.js:20440:22)
at beginWork (react-dom.development.js:22376:18)
at HTMLUnknownElement.callCallback (react-dom.development.js:4144:16)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4193:18)
at invokeGuardedCallback (react-dom.development.js:4257:33)
at beginWork$1 (react-dom.development.js:27253:9)
at performUnitOfWork (react-dom.development.js:26405:14)

路由的exact属性无效

把route路由更换为KeepaliveRoute之后,exact属性无效。比如列表页的路由:/video/study,详情页的路由:/video/study/list,这样从列表点击跳转到详情的时候,地址栏的路由发生了变化,但是页面并没有跳到详情页去

提供完整的 demo

请问可以给一个完成的可以跑起来的示例吗?你这个 KeepAliveRoute 缓存的是真实的 DOM,按照 README 里面的 gif,切换回去数字还是 8,如果在点击 add,这个数字会是 1 还是 9?

函数组件中页面表现与react的实际状态不一致

函数组件中,页面的状态与组件实际状态不一致,页面更像是一个快照,函数组件中的state都被初始化了。
函数组件有一个输入框 值为5,再次进入时页面也显示5,但是打印出来的却是初始值。感觉真实dom与react虚拟dom不一致。

scroll设置不生效

route设置scroll属性,但是监听不到parentNode的滚动,还要设置什么嘛

useParams无效

router

    <Suspense fallback={Loading}>
      <BrowserRouter>
        <KeepaliveRouterSwitch>
          <Route strict exact path="/user/login">
            <Login />
          </Route>
          <Route strict exact path="/redirect" component={Redirect404} />

          <KeepaliveRoute strict exact path="/patient/list">
            <Layout>
              <List />
            </Layout>
          </KeepaliveRoute>
          <KeepaliveRoute strict exact path="/patient/:id/record/overview">
            <Layout>
              <ListStudy />
            </Layout>
          </KeepaliveRoute>
          <KeepaliveRoute strict exact path="/patient/analysis">
            <Layout>
              <Analysis />
            </Layout>
          </KeepaliveRoute>
          <Redirect from="/*" to="/redirect" />
        </KeepaliveRouterSwitch>
      </BrowserRouter>
    </Suspense>

使用

import { useParams } from 'react-router-dom';
 const { id } = useParams();
// ?undefined

建议

希望可以增加保存滚动位置的功能
是否可以将快弃用的钩子修改为UNSAFE的形式,我控制台总是报componentWillReceiveProps的警告

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.