fix(ssr): remove context

This commit is contained in:
qingwei.li 2017-05-30 06:32:41 +08:00
commit 46261572e3
No known key found for this signature in database
GPG key ID: B6DDC2F7AE80B2F4
12 changed files with 58 additions and 59 deletions

View file

@ -50,6 +50,7 @@ export function fetchMixin (proto) {
const root = getParentPath(this.route.path)
const path = this.router.getFile(root + coverpage)
console.log(this.route.path, root, path)
if (this.route.path !== '/' || !coverpage) {
this._renderCover()
return

View file

@ -4,7 +4,7 @@ import { helper as helperTpl, tree as treeTpl } from './tpl'
import { genTree } from './gen-tree'
import { slugify } from './slugify'
import { emojify } from './emojify'
import { getBasePath, isAbsolutePath, getPath } from '../router/util'
import { isAbsolutePath, getPath } from '../router/util'
import { isFn, merge, cached } from '../util/core'
export class Compiler {
@ -14,7 +14,7 @@ export class Compiler {
this.cacheTree = {}
this.toc = []
this.linkTarget = config.externalLinkTarget || '_blank'
this.contentBase = getBasePath(config.basePath)
this.contentBase = router.getBasePath()
const renderer = this._initRenderer()
let compile

View file

@ -5,7 +5,7 @@ import tinydate from 'tinydate'
import { callHook } from '../init/lifecycle'
import { Compiler } from './compiler'
import { getAndActive, sticky } from '../event/sidebar'
import { getBasePath, getPath, isAbsolutePath } from '../router/util'
import { getPath, isAbsolutePath } from '../router/util'
import { isMobile } from '../util/env'
import { isPrimitive } from '../util/core'
import { scrollActiveSidebar, scroll2Top } from '../event/scroll'
@ -143,7 +143,7 @@ export function renderMixin (proto) {
dom.toggleClass(el, 'add', 'has-mask')
if (!isAbsolutePath(m[1])) {
path = getPath(getBasePath(this.config.basePath), m[1])
path = getPath(vm.router.getBasePath(), m[1])
}
el.style.backgroundImage = `url(${path})`
el.style.backgroundSize = 'cover'

View file

@ -1,4 +1,4 @@
import { getBasePath, getPath, isAbsolutePath } from '../util'
import { getPath, isAbsolutePath } from '../util'
import { noop } from '../../util/core'
function getAlias (path, alias) {
@ -18,9 +18,13 @@ export class History {
this.config = config
}
getBasePath() {
return this.config.basePath
}
getFile (path) {
const { config } = this
const base = getBasePath(config.basePath)
const base = this.getBasePath()
path = config.alias ? getAlias(path, config.alias) : path
path = getFileName(path)

View file

@ -20,6 +20,15 @@ export class HashHistory extends History {
this.mode = 'hash'
}
getBasePath() {
const path = window.location.pathname || ''
const base = this.config.basePath
return /^(\/|https?:)/g.test(base)
? base
: cleanPath(path + '/' + base)
}
getCurrentPath () {
// We can't use location.hash here because it's not
// consistent across browsers - Firefox will pre-decode it!

View file

@ -1,5 +1,4 @@
import { cached } from '../util/core'
import { inBrowser } from '../util/env'
const decode = decodeURIComponent
const encode = encodeURIComponent
@ -32,15 +31,6 @@ export function stringifyQuery (obj) {
return qs.length ? `?${qs.join('&')}` : ''
}
export const getBasePath = cached((base = '') => {
// TODO
const path = inBrowser ? window.location.pathname : ''
return /^(\/|https?:)/g.test(base)
? base
: cleanPath(path + '/' + base)
})
export function getPath (...args) {
return cleanPath(args.join('/'))
}