Static GitHub Issues

[867] importing router instance using alias not working properly

prev: In the nuxt I need the server database related operations, I was in the plugins, or in the middleware?
next: How can I create public js and multiple components can include it

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?

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c743">#c743</a>)</em></sub></div>