title: Nuxt and router.js: How to add router.beforeEach() guards?
body: <p>I am using a <code>router.js</code> file (from <code>@nuxtjs/router</code> module) to handle my routes instead of Nuxt's <code>pages</code> directory structure.</p>
  <p>How/Where would I add the following code in the <code>router.js</code> file?</p>
  <pre><code>router.beforeEach((to, from, next) =&gt; {
    const requiresAuth = to.matched.some(x =&gt; x.meta.requiresAuth)
    const currentUser = auth.currentUser
    // If the route requires authentication, and the user is not signed-in, then redirect the user to the Login view to enter their credentials, and sign-in to the app before visiting the route.
    if (requiresAuth &amp;&amp; !currentUser) next('/login')
  ...snip..
  </code></pre>
  <p>My current <code>router.js</code> structure is like so:</p>
  <pre><code>..snip..
  Vue.use(Router)
  
  export function createRouter() {
    return new Router({
      mode: 'history',
      routes: [
        ...snip..
      ]
    })
  }
  </code></pre>
  <p>Thanks for any help!</p>