forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.js
More file actions
50 lines (43 loc) · 1.34 KB
/
router.js
File metadata and controls
50 lines (43 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const trailingSlashRE = /\/?$/
function equals (current, target) {
if (Object.keys(current).length !== Object.keys(target).length) {
return false
}
// route query and params are strings when read from URL
for (const key in target) {
if (!(key in current) || String(current[key]) !== String(target[key])) {
return false
}
}
return true
}
function includes (current, target) {
for (const key in target) {
if (!(key in current)) {
return false
}
}
return true
}
export function isSameRoute (current, target) {
if (!target) {
return false
}
if (current.path && target.path) {
return (
current.path.replace(trailingSlashRE, '') === target.path.replace(trailingSlashRE, '') &&
current.hash === target.hash &&
equals(current.query, target.query)
)
}
return typeof current.name === 'string' &&
current.name === target.name &&
current.hash === target.hash &&
equals(current.query, target.query) === true &&
equals(current.params, target.params) === true
}
export function isIncludedRoute (current, target) {
return current.path.replace(trailingSlashRE, '/').indexOf(target.path.replace(trailingSlashRE, '/')) === 0 &&
(typeof target.hash !== 'string' || target.hash.length < 2 || current.hash === target.hash) &&
includes(current.query, target.query) === true
}