Nuxt.js: importing router instance using alias not working properly

Created on 9 Jun 2017  路  3Comments  路  Source: nuxt/nuxt.js

I'm using the example ga implementation from the nuxt official website

when I use import router from '~router' and define router.afterEach, I get this error:

[nuxt.js] Cannot load components TypeError: Cannot read property 'afterEach' of undefined

when I use const router = require('~router'), I get this error:

[nuxt.js] Cannot load components TypeError: __webpack_require__(...) is not a function

Question: how to properly import router instance to get google analytics working?

This question is available on Nuxt.js community (#c743)

Most helpful comment

Hi @zzhjerry . Because of new changes to Vue SSR engine, there is no longer a good way using singleton and globals. For GA, you may try google-analytics module which is compatible with 1.x too.

All 3 comments

Hi @zzhjerry . Because of new changes to Vue SSR engine, there is no longer a good way using singleton and globals. For GA, you may try google-analytics module which is compatible with 1.x too.

Hi @pi0 it worked! thanks!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bimohxh picture bimohxh  路  3Comments

shyamchandranmec picture shyamchandranmec  路  3Comments

surmon-china picture surmon-china  路  3Comments

pehbehbeh picture pehbehbeh  路  3Comments

danieloprado picture danieloprado  路  3Comments