1 Star 0 Fork 28

Zy/mulanbay-mobile-vue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.js 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
牧羊人 提交于 2021-02-25 13:36 +08:00 . 初始化提交
import Vue from 'vue'
import Router from 'vue-router'
import { constantRouterMap } from './router.config.js'
// hack router push callback
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}
Vue.use(Router)
const createRouter = () =>
new Router({
// 新增base配置 解决项目名称问题
//base: '/vuem',
mode: 'history', // 如果你是 history模式 需要配置vue.config.js publicPath
// base: process.env.BASE_URL,
//如果keepAlive的话,返回时定位在原来的位置
scrollBehavior (to, from, savedPosition) {
if (savedPosition) {
return savedPosition
} else {
if (from.meta.keepAlive) {
from.meta.savedPosition = document.body.scrollTop;
}
return { x: 0, y: to.meta.savedPosition ||0}
}
},
routes: constantRouterMap
})
const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
const newRouter = createRouter()
router.matcher = newRouter.matcher // reset router
}
export default router
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/Zhlaa/mulanbay-mobile-vue.git
git@gitee.com:Zhlaa/mulanbay-mobile-vue.git
Zhlaa
mulanbay-mobile-vue
mulanbay-mobile-vue
master

搜索帮助