在后退时,根路由器上安装了第二个 BUG
import UTILS from "./utils"; import { f7 } from 'framework7-vue';
function getRouter() { let router = null; if (window && window.document) { const mainViewEl = document.querySelector('#framework7-root .view-main'); if (mainViewEl && mainViewEl.f7View) { router = mainViewEl.f7View.router; console.log("get route from dom!"); } } if (!router && f7) { try { const currentView = f7.views?.current || f7.instance?.currentView; if (currentView) { router = currentView.router; console.log("get route from router!"); } } catch (e) { console.warn('[F7 Router] Fallback to f7 instance failed: ', e); } } return router; }
function getRoute() { const router = getRouter(); let route = { path: '', query: {}, url: '' }; if (router) { if (router.currentRoute) { route = router.currentRoute; } } return route; }
function getCurrentPath() { const route = getRoute(); let path = ''; if (route) { path = route.path; } return path; }
export default { open(link, params) { const router = getRouter(); if (!router) { console.warn('[F7 Router] Router instance not initialized, cannot navigate'); return; } let toPath = ''; let toParams = {}; if (UTILS.isString(link) && link) { toPath = link; toParams = params || {}; } else if (UTILS.isObject(link) && link.url) { toPath = link.url; toParams = link.params || link.param || {}; } else { console.warn('[F7 Router] no router link offered!'); return; } const url = UTILS.url.make(toPath, { d: JSON.stringify(toParams) }); router.navigate(url, { animate: true, preventDuplicate: true }); },
back(params) { console.log("exec back begin..."); const router = getRouter(); if (!router) { console.warn('[F7 Router] Router instance not initialized, cannot go back'); return; } const historyLen = router.history?.length || 0; if (historyLen <= 1) { console.log('[F7 Router] 无历史页面可回退,禁止操作'); return; } const currentPath = getCurrentPath(); if (currentPath === '/') { console.log('[F7 Router] Current path is root /, back is forbidden'); return; } const backOptions = { animate: true, reload: false }; console.log("run back logic", backOptions); …
内容来源: framework7io/framework7