Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Scroll to anchor not working #213 #214

Merged
merged 6 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/saber/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"cac": "^6.5.1",
"chokidar": "^3.0.0",
"css-loader": "^2.1.0",
"css.escape": "^1.5.1",
"cssnano": "^4.1.8",
"devalue": "^1.1.0",
"fast-deep-equal": "^2.0.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/saber/vue-renderer/app/create-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ export default context => {
delete transition[key]
}
})
const beforeEnter = listeners['before-enter']
listeners['before-enter'] = el => {
const afterEnter = listeners['after-enter']
listeners['after-enter'] = el => {
this.$emit('trigger-scroll')
beforeEnter && beforeEnter(el)
afterEnter && afterEnter(el)
krmax44 marked this conversation as resolved.
Show resolved Hide resolved
}
const children = [
h(
Expand Down
23 changes: 6 additions & 17 deletions packages/saber/vue-renderer/app/router.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue'
import Router from './vendor/vue-router'
import RoutePrefetch from './vendor/vue-router-prefetch'
import cssEscape from 'css.escape'
import routes from '#cache/routes'

Vue.use(Router)
Expand Down Expand Up @@ -66,23 +67,11 @@ export default () => {
// coords will be used if no selector is provided,
// or if the selector didn't match any element.
if (to.hash) {
let hash = to.hash
// CSS.escape() is not supported with IE and Edge.
if (
typeof window.CSS !== 'undefined' &&
typeof window.CSS.escape !== 'undefined'
) {
hash = '#' + window.CSS.escape(hash.substr(1))
}
try {
if (document.querySelector(hash)) {
// scroll to anchor by returning the selector
position = { selector: hash }
}
} catch (e) {
console.warn(
'Failed to save scroll position. Please add CSS.escape() polyfill (https://github.com/mathiasbynens/CSS.escape).'
)
const selector = `#${cssEscape(to.hash.substr(1))}`

if (document.querySelector(selector)) {
// scroll to anchor by returning the selector
position = { selector }
}
}
resolve(position)
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3748,6 +3748,11 @@ css-what@^2.1.2:
resolved "https://registry.npmjs.org/css-what/-/css-what-2.1.2.tgz#c0876d9d0480927d7d4920dcd72af3595649554d"
integrity sha512-wan8dMWQ0GUeF7DGEPVjhHemVW/vy6xUYmFzRY8RYqgA0JtXC9rJmbScBjqSu6dg9q0lwPQy6ZAmJVr3PPTvqQ==

css.escape@^1.5.1:
version "1.5.1"
resolved "https://registry.npmjs.org/css.escape/-/css.escape-1.5.1.tgz#42e27d4fa04ae32f931a4b4d4191fa9cddee97cb"
integrity sha1-QuJ9T6BK4y+TGktNQZH6nN3ul8s=

cssesc@^0.1.0:
version "0.1.0"
resolved "https://registry.npmjs.org/cssesc/-/cssesc-0.1.0.tgz#c814903e45623371a0477b40109aaafbeeaddbb4"
Expand Down