What is the best Vue-Router practice for very large webapplications?

后端 未结 3 984
臣服心动
臣服心动 2021-01-31 09:39

I have to make a webapplication with many different modules (like a todo-module, document-modules, and a big usermanagement-module for admin users). The total number of pages is

3条回答
  •  长情又很酷
    2021-01-31 09:59

    If you go with SPA app, please make sure you are using these practices:

    1. Lazy loading/async components. We usually do lazy loading for static assets. In the same spirit, we only need to load the components when the routes are visited. Vue will only trigger the factory function when the component needs to be rendered and will cache the result for future re-renders.
    import MainPage from './routes/MainPage.vue'
    const Page1 = r => require.ensure([], () => r(require('./routes/Page1.vue')))
    
    const routes = [
      { path: '/main', component: MainPage },
      { path: '/page1', component: Page1 }
    ]
    
    1. Combining routes: (related to above) For example, in the following case, 2 routes are output in the same chunk and bundle, causing that bundle to be lazy-loaded when either route is accessed.
    const Page1 = r => require.ensure([], () => r(require('./routes/Page1.vue')), 'big-pages')  
    const Page2 = r => require.ensure([], () => r(require('./routes/Page2.vue')), 'big-pages')
    

提交回复
热议问题