1.0 features (#21)
* feat: hash routing, close #2 * Fix router bug * Remove console * Add hash router docs * Improved scrolling on mobile * Add change log * Use hash router
This commit is contained in:
parent
b977715d42
commit
864935bfc1
15 changed files with 174 additions and 60 deletions
23
src/util.js
23
src/util.js
|
|
@ -66,3 +66,26 @@ export function camel2kebab (str) {
|
|||
export function isNil (o) {
|
||||
return o === null || o === undefined
|
||||
}
|
||||
|
||||
let cacheRoute = null
|
||||
let cacheHash = null
|
||||
|
||||
/**
|
||||
* hash route
|
||||
*/
|
||||
export function getRoute () {
|
||||
const loc = window.location
|
||||
if (cacheHash === loc.hash && !isNil(cacheRoute)) return cacheRoute
|
||||
|
||||
let route = loc.hash.match(/^#\/([^#]+)/)
|
||||
|
||||
if (route && route.length === 2) {
|
||||
route = route[1]
|
||||
} else {
|
||||
route = /^#\//.test(loc.hash) ? '' : loc.pathname
|
||||
}
|
||||
cacheRoute = route
|
||||
cacheHash = loc.hash
|
||||
|
||||
return route
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue