Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
fix(page): Ensure that calling page with a string works
Browse files Browse the repository at this point in the history
see #124

fix(page): Calling page with a router uses pageviewTemplate if set
  • Loading branch information
mwaldstein committed May 21, 2018
1 parent ce51e7b commit 65284b3
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,11 @@ export default function page (...args) {
}

if (route) {
const {
router,
autoTracking: {
transformQueryString,
prependBase
}
} = config

const queryString = getQueryString(route.query)
const base = router && router.options.base
const needsBase = prependBase && base

let path = route.path + (transformQueryString ? queryString : '')
path = needsBase ? getBasePath(base, path) : path

set('page', path)
query('send', 'pageview')
trackRoute(route)
} else {
set('page', args[0].page)
// We can call with `page('/my/path')`
let page = typeof args[0] === 'object' ? args[0].page : args[0]
set('page', page)
query('send', 'pageview', ...args)
}
}
Expand All @@ -68,7 +54,26 @@ export function trackRoute (route) {
return
}

page(proxy ? proxy(route) : route)
if (proxy) {
page(proxy(route))
} else {
const {
router,
autoTracking: {
transformQueryString,
prependBase
}
} = config

const queryString = getQueryString(route.query)
const base = router && router.options.base
const needsBase = prependBase && base

let path = route.path + (transformQueryString ? queryString : '')
path = needsBase ? getBasePath(base, path) : path

page(path)
}
}

export function autoTracking () {
Expand Down

0 comments on commit 65284b3

Please sign in to comment.