Giter Site home page Giter Site logo

Comments (3)

Boelroy avatar Boelroy commented on July 26, 2024

嗯 React Router 4 由于放弃了 createBrowserHistory 的形式,必须从 BrowserRouter 里面获取 history 对象, 可以考虑一下如下的方式。

import { BrowserRouter, withRouter } from 'react-router-dom';

const Application (props) => {
   useEffect(() => {
      const { history, path, location } = this.props;
      if (location.path !== props.path) {
        history.push(path);
      }
  }, [props.path]);

  return (
    /* 你要渲染的路由 */
  );
}

const App = withRouter(Application);

export default mount(
  (props) => (
      <BrowserRouter>
        <App {...props} />
      </BrowserRouter>
  ),
  document.getElementById('app'),
  appID
);

from alibabacloud-alfa.

junhui75165 avatar junhui75165 commented on July 26, 2024

如要要做多页面缓存的话,子应用之间的数据要缓存起来怎么做好些

from alibabacloud-alfa.

Boelroy avatar Boelroy commented on July 26, 2024

可以通过在宿主里面做个缓存池,然后通过 应用和宿主的通行 做数据的缓存。 比如在 应用写在的时候通过 事件通信 的方式存一下状态,然后在应用加载的时候 宿主 通过 props 注入 之前 子应用保存的状态

from alibabacloud-alfa.

Related Issues (20)

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.