All Projects → nuxt-community → Router Module

nuxt-community / Router Module

Licence: mit
Nuxt.js module to use router.js instead of pages/ directory.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Router Module

Hackernews
HackerNews clone built with Nuxt.js
Stars: ✭ 758 (+135.4%)
Mutual labels:  nuxt, vue-router
Naice Blog
😺 新的博客上线啦
Stars: ✭ 93 (-71.12%)
Mutual labels:  nuxt, vue-router
Nuxt Ssr Demo
✨ 高仿掘金,整合 vue + nuxt + axios + vuex + vue-router (nuxt 自带 vuex 和 vue-router),一个基于 Nuxt 的服务器端渲染 Demo
Stars: ✭ 856 (+165.84%)
Mutual labels:  nuxt, vue-router
Nuxt Elm
基于nuxt2+vue构建的全栈开源项目
Stars: ✭ 304 (-5.59%)
Mutual labels:  nuxt, vue-router
nativescript-vue-router
A simple router implementation that is suitable for NativeScript-Vue.
Stars: ✭ 14 (-95.65%)
Mutual labels:  router, vue-router
Vue Kindergarten
Modular security for Vue, Vuex, Vue-Router and Nuxt
Stars: ✭ 303 (-5.9%)
Mutual labels:  nuxt, vue-router
Laravel Vuejs.com
Laravel and VueJs Blog, using Laravel nova, GraphQL, NuxtJs, Apollo and ...more
Stars: ✭ 54 (-83.23%)
Mutual labels:  nuxt, vue-router
Vuecnodejs
⚽️🎉Vue初/中级项目,CnodeJS社区重构。( a junior project of Vue.js, rewrite cnodejs.org ) 预览(DEMO):
Stars: ✭ 705 (+118.94%)
Mutual labels:  nuxt, vue-router
Vuemmerce
👉 Responsive ecommerce template 🛒 built with Vue.js and Nuxt.js
Stars: ✭ 223 (-30.75%)
Mutual labels:  nuxt, vue-router
Vue Cheatsheet
Modified version of the official VueMastery cheatsheet
Stars: ✭ 188 (-41.61%)
Mutual labels:  nuxt, vue-router
Vue Routisan
Elegant, fluent route definitions for Vue Router, inspired by Laravel. v3 is currently in beta. [email protected]
Stars: ✭ 193 (-40.06%)
Mutual labels:  router, vue-router
nuxt-interpolation
Nuxt.js module as directive for binding every link to catch the click event, and if it's a relative link router will push.
Stars: ✭ 38 (-88.2%)
Mutual labels:  router, nuxt
Nuxt.js
The Intuitive Vue(2) Framework
Stars: ✭ 38,986 (+12007.45%)
Mutual labels:  nuxt, vue-router
Vue Soundcloud
🎧 A SoundCloud client built with Vue and Nuxt
Stars: ✭ 141 (-56.21%)
Mutual labels:  nuxt, vue-router
jooger.me
👍 My personal website,powered by @nuxt
Stars: ✭ 39 (-87.89%)
Mutual labels:  nuxt, vue-router
Vue Smart Route
Smart route search to make intelligent looking apps with Vue.js.
Stars: ✭ 280 (-13.04%)
Mutual labels:  router, vue-router
Svelte Router
Svelte Router adds routing to your Svelte apps. It's designed for Single Page Applications (SPA). Includes localisation, guards and nested layouts.
Stars: ✭ 310 (-3.73%)
Mutual labels:  router
Blog Front
blog-front @nuxt
Stars: ✭ 305 (-5.28%)
Mutual labels:  nuxt
Rxrouter
A lightweight, simple, smart and powerful Android routing library.
Stars: ✭ 320 (-0.62%)
Mutual labels:  router
Vue Router Prefetch
Prefetch links when they are visible in viewport.
Stars: ✭ 315 (-2.17%)
Mutual labels:  vue-router

@nuxtjs/router

npm version npm downloads Github Actions CI Codecov License

Nuxt.js module to use router.js instead of pages/ directory

📖 Release Notes

Features

Use your own router.js to handle your routes into your Nuxt.js application.

Setup

  1. Add @nuxtjs/router dependency to your project
yarn add --dev @nuxtjs/router # or npm install --save-dev @nuxtjs/router
  1. Add @nuxtjs/router to the buildModules section of nuxt.config.js
export default {
  buildModules: [
    // Simple usage
    '@nuxtjs/router',

    // With options
    ['@nuxtjs/router', { /* module options */ }]
  ]
}

⚠️ If you are using Nuxt < v2.9 you have to install the module as a dependency (No --dev or --save-dev flags) and use modules section in nuxt.config.js instead of buildModules.

Using top level options

export default {
  buildModules: [
    '@nuxtjs/router'
  ],
  routerModule: {
    /* module options */
  }
}

If you are using SPA mode, add an index / route to generate section of nuxt.config.js:

export default {
  generate: {
    routes: [
      '/'
    ]
  }
}

Options

path

  • Type: String
  • Default: srcDir

Location of you route file.

fileName

  • Type: String
  • Default: router.js

Name of you route file.

keepDefaultRouter

  • Type: Boolean
  • Default: false

Can access the default router.

parsePages

  • Type: Boolean
  • Default: 'keepDefaultRouter'

Can disable/enable the pages/ directory into Nuxt.

Usage

This module, by default, disable the pages/ directory into Nuxt and will use a router.js file at your srcDir directory:

components/
  my-page.vue
router.js

router.js need to export a createRouter method like this:

import Vue from 'vue'
import Router from 'vue-router'

import MyPage from '~/components/my-page'

Vue.use(Router)

export function createRouter() {
  return new Router({
    mode: 'history',
    routes: [
      {
        path: '/',
        component: MyPage
      }
    ]
  })
}

The components defined as routes have access to the same special attributes and functions (head, asyncData, validate, etc.) as the Nuxt Page component.

Accessing default router

If you use the module with { keepDefaultRouter: true }, you can access the default router:

⚠️ If you are using Nuxt < 2.9.0, the parameter routerOptions is not available.

⚠️ If you are using Nuxt < 2.15.0, the parameter config is not available.

export function createRouter(ssrContext, createDefaultRouter, routerOptions, config) {
  const options = routerOptions ? routerOptions : createDefaultRouter(ssrContext, config).options

  return new Router({
    ...options,
    routes: fixRoutes(options.routes)
  })
}

function fixRoutes(defaultRoutes) {
  // default routes that come from `pages/`
  return defaultRoutes.filter(...).map(...)
}

Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Start development server using npm run dev

License

MIT License

Copyright (c) Nuxt Community

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].