VueRouter-路由重定向和別名


  重定向:

  在定義路由的時候,可以通過添加`redirect`參數,重定向到另外一個頁面。
routes: [{
                path: "/",
                redirect: "/article"
            }]

        別名:

  在定義路由的時候,可以通過添加`alias`參數,表示該url的別名,以后也可以通過這個別名來訪問到這個組件。
        let router = new VueRouter({
            routes: [ {
                path: "/article",
                component: article,
                alias: "/list"
            }]
        })

  整體代碼:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <title>VueRouter-路由重定向和別名</title>
</head>

<body>
    <div id="app">
        <router-view></router-view>
    </div>
    <script>
        let article = Vue.extend({
            template: "<h1>文章列表</h1>"
        })
        let router = new VueRouter({
            routes: [{
                path: "/",
                redirect: "/article"
            }, {
                path: "/article",
                component: article,
                alias: "/list"
            }]
        })
        new Vue({
            el: "#app",
            router,
        })
    </script>
</body>

</html>

 

 


免責聲明!

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



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