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

Commit b09ba4c

Browse files
author
Brandon Pittman
committed
✨ Auto set OGP URL using router.beforeEach hook
Picked this idea up from DOCC
1 parent 8c227dd commit b09ba4c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

gridsome.client.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@ import ogp from './lib/ogp'
22

33
export default function (Vue) {
44
Vue.prototype.$ogp = ogp
5+
6+
router.beforeEach(to, from, next) {
7+
head.meta.push({
8+
property: 'og:url',
9+
content: process.env.GRIDSOME_BASE_PATH + to.path,
10+
})
11+
next()
12+
}
513
}

lib/ogp.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ export default function ({
4646
content: appId ? appId : ''
4747
}
4848
: {},
49-
{
50-
property: 'og:url',
51-
content: url ? url : (process.isClient ? window.location.href : '')
52-
},
5349
{
5450
property: 'og:type',
5551
content: 'website'

0 commit comments

Comments
 (0)