vue-router 与 react-router 设计理念上的区别

  • vue-router 与 react-router 设计理念上的区别:
区别 vue-router react-router
改成history mode: 'history' 直接使用 react-router 的话,用 BrowserRouter 将<App>包裹起来,或引入history(推荐,history可用于页面组件之外导航,此时就可以不用react-router-redux)
  • 页面组件之外导航,2种实现方式:
  1. react-router-redux
    react-router-redux 让你可以在任何地方通过 dispatch 处理页面跳转,如:store.dispatch(push('/'))
  2. history
    安装npm install history;
    不使用 react-router-dom 提供的 BrowserRouter 而是自己实现一个。
    history.js:
import createHistory from 'history/createBrowserHistory';
const history = createHistory();
export default history;

组件内引用:

import history from './history';

组件内使用:

 history.push('/')

在任何地方只要引用 history 就可以使用它进行导航操作,如 history.push('/')

原文地址:https://www.cnblogs.com/cag2050/p/8697633.html