Skip to content

Instantly share code, notes, and snippets.

@LissetteIbnz
Last active September 28, 2018 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LissetteIbnz/8297ef5f1d3aa5f517293797dcfa05c0 to your computer and use it in GitHub Desktop.
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
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,
},
];
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,
});
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,
},
];
// 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