Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 65284b3

Browse files
committed
fix(page): Ensure that calling page with a string works
see #124 fix(page): Calling page with a router uses pageviewTemplate if set
1 parent ce51e7b commit 65284b3

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/lib/page.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,11 @@ export default function page (...args) {
2525
}
2626

2727
if (route) {
28-
const {
29-
router,
30-
autoTracking: {
31-
transformQueryString,
32-
prependBase
33-
}
34-
} = config
35-
36-
const queryString = getQueryString(route.query)
37-
const base = router && router.options.base
38-
const needsBase = prependBase && base
39-
40-
let path = route.path + (transformQueryString ? queryString : '')
41-
path = needsBase ? getBasePath(base, path) : path
42-
43-
set('page', path)
44-
query('send', 'pageview')
28+
trackRoute(route)
4529
} else {
46-
set('page', args[0].page)
30+
// We can call with `page('/my/path')`
31+
let page = typeof args[0] === 'object' ? args[0].page : args[0]
32+
set('page', page)
4733
query('send', 'pageview', ...args)
4834
}
4935
}
@@ -68,7 +54,26 @@ export function trackRoute (route) {
6854
return
6955
}
7056

71-
page(proxy ? proxy(route) : route)
57+
if (proxy) {
58+
page(proxy(route))
59+
} else {
60+
const {
61+
router,
62+
autoTracking: {
63+
transformQueryString,
64+
prependBase
65+
}
66+
} = config
67+
68+
const queryString = getQueryString(route.query)
69+
const base = router && router.options.base
70+
const needsBase = prependBase && base
71+
72+
let path = route.path + (transformQueryString ? queryString : '')
73+
path = needsBase ? getBasePath(base, path) : path
74+
75+
page(path)
76+
}
7277
}
7378

7479
export function autoTracking () {

0 commit comments

Comments
 (0)