1- import { route } from "quasar/wrappers" ;
1+ import { route } from 'quasar/wrappers'
2+ // import { nextTick } from 'vue'
23import {
34 createRouter ,
45 createMemoryHistory ,
56 createWebHistory ,
67 createWebHashHistory ,
7- } from " vue-router" ;
8- import routes from " ./routes" ;
8+ } from ' vue-router'
9+ import routes from ' ./routes'
910
1011/*
1112 * If not building with SSR mode, you can
@@ -19,16 +20,27 @@ import routes from "./routes";
1920export default route ( function ( /* { store, ssrContext } */ ) {
2021 const createHistory = process . env . SERVER
2122 ? createMemoryHistory
22- : process . env . VUE_ROUTER_MODE === " history"
23- ? createWebHistory
24- : createWebHashHistory ;
23+ : process . env . VUE_ROUTER_MODE === ' history'
24+ ? createWebHistory
25+ : createWebHashHistory
2526
2627 const Router = createRouter ( {
2728 // scrollBehavior: () => ({ left: 0, top: 0 }),
2829 // https://router.vuejs.org/guide/advanced/scroll-behavior.html#Scroll-Behavior
2930 // scrollBehavior(to, from, savedPosition) {
30- scrollBehavior ( to , ) {
31+ scrollBehavior ( to ) {
3132 if ( to . hash ) {
33+ // https://router.vuejs.org/guide/advanced/scroll-behavior.html#Delaying-the-scroll
34+ // return new Promise((resolve) => {
35+ // setTimeout(() => {
36+ // resolve({
37+ // el: to.hash,
38+ // behavior: 'smooth',
39+ // })
40+ // }, 500)
41+ // })
42+ // this does not really work.
43+ // seems the md content is not rendered fast enough...
3244 return {
3345 el : to . hash ,
3446 behavior : 'smooth' ,
@@ -43,5 +55,23 @@ export default route(function (/* { store, ssrContext } */) {
4355 history : createHistory ( process . env . VUE_ROUTER_BASE ) ,
4456 } )
4557
46- return Router ;
47- } ) ;
58+ // https://stackoverflow.com/questions/62409643/scroll-to-anchor-on-refresh-or-on-manual-url-change?noredirect=1&lq=1
59+ // Router.afterEach((to, from) => {
60+ // if (to.hash && to.path != from.path) {
61+ // // Vue.nextTick().then(() => VueScrollTo.scrollTo(to.hash, 700))
62+ // nextTick().then(() => {
63+ // setTimeout(() => {
64+ // // console.log(`to.hash.replace('#', '')`, to.hash.replace('#', ''))
65+ // const target = document.getElementById(to.hash.replace("#", ''))
66+ // // console.log('target', target)
67+ // // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
68+ // target.scrollIntoView({
69+ // behavior: 'smooth',
70+ // })
71+ // }, 200);
72+ // })
73+ // }
74+ // })
75+
76+ return Router
77+ } )
0 commit comments