|
|
@ -7,8 +7,8 @@ import { getScrollOffset, inBrowser, withBase } from './utils'
|
|
|
|
|
|
|
|
|
|
|
|
export interface Route {
|
|
|
|
export interface Route {
|
|
|
|
path: string
|
|
|
|
path: string
|
|
|
|
hash?: string
|
|
|
|
hash: string
|
|
|
|
query?: string
|
|
|
|
query: string
|
|
|
|
data: PageData
|
|
|
|
data: PageData
|
|
|
|
component: Component | null
|
|
|
|
component: Component | null
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -57,6 +57,8 @@ const fakeHost = 'http://a.com'
|
|
|
|
|
|
|
|
|
|
|
|
const getDefaultRoute = (): Route => ({
|
|
|
|
const getDefaultRoute = (): Route => ({
|
|
|
|
path: '/',
|
|
|
|
path: '/',
|
|
|
|
|
|
|
|
hash: '',
|
|
|
|
|
|
|
|
query: '',
|
|
|
|
component: null,
|
|
|
|
component: null,
|
|
|
|
data: notFoundPageData
|
|
|
|
data: notFoundPageData
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -108,6 +110,7 @@ export function createRouter(
|
|
|
|
route.data = import.meta.env.PROD
|
|
|
|
route.data = import.meta.env.PROD
|
|
|
|
? markRaw(__pageData)
|
|
|
|
? markRaw(__pageData)
|
|
|
|
: (readonly(__pageData) as PageData)
|
|
|
|
: (readonly(__pageData) as PageData)
|
|
|
|
|
|
|
|
syncRouteQueryAndHash(targetLoc)
|
|
|
|
|
|
|
|
|
|
|
|
if (inBrowser) {
|
|
|
|
if (inBrowser) {
|
|
|
|
nextTick(() => {
|
|
|
|
nextTick(() => {
|
|
|
@ -160,14 +163,18 @@ export function createRouter(
|
|
|
|
.replace(/^\//, '')
|
|
|
|
.replace(/^\//, '')
|
|
|
|
: '404.md'
|
|
|
|
: '404.md'
|
|
|
|
route.data = { ...notFoundPageData, relativePath }
|
|
|
|
route.data = { ...notFoundPageData, relativePath }
|
|
|
|
|
|
|
|
syncRouteQueryAndHash(targetLoc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function syncRouteQueryAndHash() {
|
|
|
|
function syncRouteQueryAndHash(
|
|
|
|
if (!inBrowser) return
|
|
|
|
loc: { search: string; hash: string } = inBrowser
|
|
|
|
route.query = location.search
|
|
|
|
? location
|
|
|
|
route.hash = decodeURIComponent(location.hash)
|
|
|
|
: { search: '', hash: '' }
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
route.query = loc.search
|
|
|
|
|
|
|
|
route.hash = decodeURIComponent(loc.hash)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (inBrowser) {
|
|
|
|
if (inBrowser) {
|
|
|
|