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;

组件内引用:vue

import history from './history';

组件内使用:react

history.push('/')

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

相关文章
相关标签/搜索