Skip to content

[vue] 怎样动态加载路由? #375

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

[vue] 怎样动态加载路由?

Activity

Sihan-Tan

Sihan-Tan commented on Jul 24, 2019

@Sihan-Tan

router.addRoutes

zlqGitHub

zlqGitHub commented on Dec 23, 2019

@zlqGitHub

image

lancelote-zpc

lancelote-zpc commented on Mar 19, 2020

@lancelote-zpc
<div id="first">
    <router-link to="/a">老八一号</router-link>
    <router-link to="/b">老八二号</router-link>
    <router-link to="/c">老八三号</router-link>
    <router-link to="/d">老八四号</router-link>
    <router-view></router-view>
</div>
<script>
    let a={
        template:`<h1>奥里给 干了 兄弟们</h1>`
    };
    let b={
        template:`<h2>虽然不是同一个时间,但是是同一个撤所儿</h2>`
    };
    let c={
        template:`<h3>就吃老八秘制晓汉堡儿</h3>`
    };
    let d={
        template:`<h2>老八秘制晓汉堡  既便宜它还管饱</h2>`
    };

    let routerObj=new VueRouter({
        routes:[
            {path:'/a',component:a,name:'一号'},
            {path:'/b',component:b,name:'二号'}
        ]
    });
    routerObj.addRoutes([
        {path:'/c',component:c,name:'三号'},
        {path:'/d',component:d,name:'四号'}
    ]);
    let vm=new Vue({
        el:"#first",
        data:{},
        router:routerObj
    })
</script>

vue-router的addRoutes方法

WenJieLi1998

WenJieLi1998 commented on Apr 19, 2020

@WenJieLi1998

router.addRoutes

Drikold

Drikold commented on Jul 26, 2021

@Drikold

动态添加路由:router.addRoute
动态加载路由->懒加载?

const Foo = () => import('./Foo.vue')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@Drikold@Sihan-Tan@WenJieLi1998@zlqGitHub

        Issue actions

          [vue] 怎样动态加载路由? · Issue #375 · haizlin/fe-interview