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('/')


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM