Ionic 在单独的文件中定义路由并在index.js中使用它们

cygmwpex  于 2022-12-20  发布在  Ionic
关注(0)|答案(1)|浏览(142)

我的index.js中有这些路由

import {
    createRouter,
    createWebHistory
}
from '@ionic/vue-router';
import {
    RouteRecordRaw
}
from 'vue-router';

const routes = [{
        path: '',
        redirect: '/tabs'
    }, {
        path: '/tabs',
        component: () => import('../views/tabs/TabRoot.vue'),
        children: [{
                path: '',
                redirect: '/tabs/home'
            }, {
                path: '/tabs/home',
                component: () => import('../views/tabs/Home.vue')
            }, 
        ]
    },

   //Sell
   
    {
        path: '/sell',
        component: () => import('../views/pages/sell/Sell.vue')
    },

    //Categories
    
    {
        path: '/trending',
        component: () => import('../views/pages/Trending.vue')
    }
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

export default router

并且我想定义以下路由isnide others.js文件并将其包含在内

{
    path: '/crud_ui_landing_vehicles',
    component: () => import('../views/pages/sell/categories/Vehicles.vue')
},

{
    path: '/crud_ui_landing_properties',
    component: () => import('../views/pages/sell/categories/Properties.vue')
},

导入的路径应该在const routes数组对象内部使用,如何定义和导入路径文件?

sh7euo9m

sh7euo9m1#

使用传播运算符

// others.js
export const others = [...]
import { others } from './others.js'
const routes = [
  ...others,
  👆
  {
    path: ...,
    component: ...
  },
  ...
]

相关问题