fix: incorrect active link (#281)

* fix scroll issue in IE

* add meta tag for IE browser

* fix link render issue after page refreshing

* fix issue of incorrect active link

Should use both `path` and `id` to identify link, as `id` might not be unique under different paths
This commit is contained in:
LaySent 2017-10-15 21:25:49 +08:00 committed by cinwell.li
commit a3ab37952d
3 changed files with 10 additions and 5 deletions

View file

@ -5,7 +5,7 @@ import { scrollIntoView } from './scroll'
export function eventMixin (proto) {
proto.$resetEvents = function () {
scrollIntoView(this.route.query.id)
scrollIntoView(this.route.path, this.route.query.id)
sidebar.getAndActive(this.router, 'nav')
}
}

View file

@ -68,6 +68,10 @@ function highlight () {
}
}
function getNavKey (path, id) {
return `${path}?id=${id}`
}
export function scrollActiveSidebar (router) {
const cover = dom.find('.cover.show')
coverHeight = cover ? cover.offsetHeight : 0
@ -82,7 +86,8 @@ export function scrollActiveSidebar (router) {
let href = a.getAttribute('href')
if (href !== '/') {
href = router.parse(href).query.id
const { query: { id }, path } = router.parse(href)
if (id) href = getNavKey(path, id)
}
if (href) nav[decodeURIComponent(href)] = li
@ -100,13 +105,13 @@ export function scrollActiveSidebar (router) {
})
}
export function scrollIntoView (id) {
export function scrollIntoView (path, id) {
if (!id) return
const section = dom.find('#' + id)
section && scrollTo(section)
const li = nav[id]
const li = nav[getNavKey(path, id)]
const sidebar = dom.getNode('.sidebar')
const active = dom.find(sidebar, 'li.active')
active && active.classList.remove('active')

View file

@ -55,7 +55,7 @@ export class HashHistory extends History {
let query = ''
const hashIndex = path.indexOf('#')
if (hashIndex) {
if (hashIndex >= 0) {
path = path.slice(hashIndex + 1)
}