refactor(core): fix route path
This commit is contained in:
parent
8cae16539d
commit
e2b7b976cf
16 changed files with 125 additions and 444 deletions
|
|
@ -3,7 +3,7 @@ import { cached } from '../util/core'
|
|||
const decode = decodeURIComponent
|
||||
const encode = encodeURIComponent
|
||||
|
||||
export const parseQuery = cached(query => {
|
||||
export function parseQuery (query) {
|
||||
const res = {}
|
||||
|
||||
query = query.trim().replace(/^(\?|#|&)/, '')
|
||||
|
|
@ -19,7 +19,7 @@ export const parseQuery = cached(query => {
|
|||
res[parts[0]] = decode(parts[1])
|
||||
})
|
||||
return res
|
||||
})
|
||||
}
|
||||
|
||||
export function stringifyQuery (obj) {
|
||||
const qs = []
|
||||
|
|
@ -37,6 +37,14 @@ export const getBasePath = cached(base => {
|
|||
: cleanPath(window.location.pathname + '/' + base)
|
||||
})
|
||||
|
||||
export function getPath (...args) {
|
||||
const path = args.find(path => /:|(\/{2})/.test(path))
|
||||
|
||||
if (path) return path
|
||||
|
||||
return cleanPath(args.join('/'))
|
||||
}
|
||||
|
||||
export const getRoot = cached(path => {
|
||||
return /\/$/g.test(path) ? path : path.match(/(\S*\/)[^\/]+$/)[1]
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue