Webpack three ways to implement lazy loading of routes

Source: Internet
Author: User

Original directions: 78727063

The first type:

Introduction Method (Normal introduction):

New Router ({    routes: [        {           '/hyh ',           component:hyh,           ' Hyh '        }    ]})

The second type:

New Router ({    routes: [         {               '/index ',               + = {                   require (['... /components/index/index '], resolve)//  Here is your module without import to introduce                }           }    ]} )

The third type: Official recommendation

// R is resolve . List = r + = Require.ensure ([], () = R (Require ('.. /components/list/list '), ' list ');  // routing is also a normal  notation New Router ({    routes: [        {           '/list/blog ',           component:list,           ' blog '         }    ]})

Describes a way to manage routing

// define an array of routes similar to a whitelist blacklist

Const DEFAULTROUTERARR = ['/list/share ']

Router.beforeeach(to, from , next) = = {

if the array is matched to this

if (Defaultrouterarr.indexof (to.path) >= 0) {

// perform various operations such as getting him to log in, not letting her in. Control detailed reference Vue routing with the Next method

Next ()

} Else {

Next ()

       }

})

Webpack three ways to implement lazy loading of routes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.