Vue2.0路由嵌套


<script>
        //組件
        const Home = {
            template:'<h3>我是主頁</h3>'
        };
        const Users = {
            template:`
            <div>
                <h3>我是用戶信息</h3>
                <ul>
                    <li><router-link to="/users/teemo">teemo</router-link>
                    </li>
                </ul>
                <div>
                    <router-view></router-view>        
                </div>    
            </div>
            
            `
        }
        const About = {
            template:'<h3>我是關於</h3>'
        }
        const Teemo={
            template:'<div>提莫</div>'
        }
        //配置路由
        const routes = [ 
            {path:'/home', component :Home},
            {
                path:'/users', 
                component:Users,
                children:[{path:'teemo',component:Teemo}]
            },
            {path:'/about',component:About},
            //404重定向
            {path:'*',redirect:'/home'}
        ]
        //生成路由實例
        const router = new VueRouter({
            routes
        })
        //掛載到vue上
        new Vue({
            router,
            el:'#box'
        })
    </script>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM