user specified base then add base in html head

This commit is contained in:
ausir 2017-05-17 00:58:27 +08:00
parent 0d9627b488
commit 50a8648eeb
2 changed files with 5 additions and 1 deletions

View File

@ -42,6 +42,7 @@ class Nuxt {
router: {
mode: 'history',
base: '/',
userSpecifiedBase: false,
middleware: [],
linkActiveClass: 'nuxt-link-active',
linkExactActiveClass: 'nuxt-link-exact-active',
@ -62,6 +63,7 @@ class Nuxt {
// Sanitization
if (options.loading === true) delete options.loading
if (options.router && typeof options.router.middleware === 'string') options.router.middleware = [ options.router.middleware ]
if (options.router && typeof options.router.base === 'string') options.router.userSpecifiedBase = true
if (typeof options.transition === 'string') options.transition = { name: options.transition }
this.options = _.defaultsDeep(options, defaults)
// Env variables

View File

@ -94,7 +94,9 @@ export async function renderRoute (url, context = {}) {
}
const m = context.meta.inject()
let HEAD = m.meta.text() + m.title.text() + m.link.text() + m.style.text() + m.script.text() + m.noscript.text()
HEAD += `<base href="${self.options.router.base}">`
if (self.options.router.userSpecifiedBase) {
HEAD += `<base href="${self.options.router.base}">`
}
HEAD += context.renderResourceHints() + context.renderStyles()
APP += `<script type="text/javascript">window.__NUXT__=${serialize(context.nuxt, { isJSON: true })}</script>`
APP += context.renderScripts()