const Foo = { template: '<div>foo</div>' }
 const Bar = { template: '<div>bar</div>' }

        const router = new VueRouter({
            routes:[
                {path: '/', component: Foo},
                {path: '/bar', component: Bar},
                {path: '/foo/:id', redirect: '/'}
            ]
        })

let vm = new Vue({
            el: '#app',
            data: {

            },
            methods: {

            },
            components: {

            },
            router
        })

 

动态路由

规则如果有接收参数

{ path: '/foo/:id', component: Foo }

编程式,也要带参才正常显示

this.$router.push('/foo/1')
 

动态路由获取参数的方法

$route.params.id

 

posted on 2020-09-11 16:33  京鸿一瞥  阅读(202)  评论(0)    收藏  举报