VueRouter- routing redirection and aliases

  Redirect:

  When the route is defined, by adding `redirect` parameter, a redirection to another page.
routes: [{
                path: "/",
                redirect: "/article"
            }]

        Alias:

  When the route is defined, by adding `alias` parameter indicates that the url alias, can also be accessed after the assembly through this alias.
        let router = new VueRouter({
            routes: [ {
                path: "/article",
                component: article,
                alias: "/list"
            }]
        })

  Overall Code:

<!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>title</VueRouter- route redirection alias and>
</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>

 

 

Guess you like

Origin www.cnblogs.com/xshan/p/12363668.html