Last active
September 28, 2018 09:52
-
-
Save LissetteIbnz/8297ef5f1d3aa5f517293797dcfa05c0 to your computer and use it in GitHub Desktop.
Ejemplo de cómo dividir las rutas de una aplicación VueJs con VueRouter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { RouteConfig } from 'vue-router'; | |
const Home = () => import(/* webpackChunkName: "home" */ '../views/Home.vue'); | |
const About = () => import(/* webpackChunkName: "about" */ '../views/About.vue'); | |
export const HomeRoutes: RouteConfig[] = [ | |
{ | |
path: '/', | |
name: 'home', | |
component: Home, | |
}, | |
{ | |
path: '/about', | |
name: 'about', | |
component: About, | |
}, | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue'; | |
import VueRouter, { RouteConfig } from 'vue-router'; | |
import { HomeRoutes } from './home'; | |
import { ResourcesRoutes } from './resources'; | |
Vue.use(VueRouter); | |
const routes: RouteConfig[] = [ | |
...HomeRoutes, | |
...ResourcesRoutes, | |
]; | |
export default new VueRouter({ | |
mode: 'history', | |
routes, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { RouteConfig } from 'vue-router'; | |
const ResourcesIndex = () => | |
import(/* webpackChunkName: "resources" */ '../views/resources/Index.vue'); | |
const ResourcesCreateOrUpdate = () => | |
import(/* webpackChunkName: "resources" */ '../views/resources/CreateOrUpdate.vue'); | |
export const ResourcesRoutes: RouteConfig[] = [ | |
{ | |
path: '/resources', | |
name: 'resources', | |
component: ResourcesIndex, | |
}, | |
{ | |
path: '/resources/add', | |
name: 'resources-create', | |
component: ResourcesCreateOrUpdate, | |
}, | |
{ | |
path: '/resources/edit/:id', | |
name: 'resources-edit', | |
component: ResourcesCreateOrUpdate, | |
}, | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Configuración sin división de rutas | |
import Vue from 'vue'; | |
import Router from 'vue-router'; | |
const Home = () => import(/* webpackChunkName: "home" */ './views/Home.vue'); | |
const About = () => import(/* webpackChunkName: "about" */ './views/About.vue'); | |
const ResourcesIndex = () => import(/* webpackChunkName: "resources" */ './views/resources/Index.vue'); | |
const ResourcesCreateOrUpdate = () => import(/* webpackChunkName: "resources" */ './views/resources/CreateOrUpdate.vue'); | |
Vue.use(Router); | |
export default new Router({ | |
mode: 'history', | |
routes: [ | |
{ | |
path: '/', | |
name: 'home', | |
component: Home, | |
}, | |
{ | |
path: '/about', | |
name: 'about', | |
component: About, | |
}, | |
{ | |
path: '/resources', | |
name: 'resources', | |
component: ResourcesIndex, | |
}, | |
{ | |
path: '/resources/add', | |
name: 'resources-create', | |
component: ResourcesCreateOrUpdate, | |
}, | |
{ | |
path: '/resources/edit/:id', | |
name: 'resources-edit', | |
component: ResourcesCreateOrUpdate, | |
}, | |
], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment