关于vue跳转,以及如果写框架时候,保留左边和顶部

app.vue

<template>

  <RouterView></RouterView>

</template>

HomeView.vue

<template>

    <div>

        this is home

        <RouterView></RouterView>

    </div>

</template>

<script setup>

</script>

<style  scoped>

</style>

MySubItemView.vue

HelloWorld.vue

<script setup>

import { ref } from 'vue'

defineProps({

  msg: String

})

const count = ref(0)

</script>

<template>

  <h1>{{ msg }}</h1>

  <p>

    Recommended IDE setup:

    <a href="https://code.visualstudio.com/" target="_blank">VSCode</a>

    +

    <a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>

  </p>

  <p>

    <a href="https://vitejs.dev/guide/features.html" target="_blank">

      Vite Documentation

    </a>

    |

    <a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>

  </p>

  <button type="button" @click="count++">count is: {{ count }}</button>

  <p>

    Edit

    <code>components/HelloWorld.vue</code> to test hot module replacement.

  </p>

</template>

<style scoped>

a {

  color: #42b983;

}

</style>

router.js

import {createRouter,createWebHashHistory} from 'vue-router';

const routes =[

    {

        path:'/',

        name:"root",

        redirect:'/home'

    },

    {

        path:'/home',

        name:"home",

        redirect: '/home/item',//这个redirect必须是跳转子,才能保留框架

        // redirect: '/hello',如果是跳转到/hello,就不能保留  this is home

        component:()=>import("../components/HomeView.vue"),

        children:[

            {

                path:'item',

                name:'item',

                component:()=>import("../components/MySubItemView.vue"),

            }

           

        ]

         

    },

    {

        path:'/hello',

        name:"hello",

        component:()=>import("../components/HelloWorld.vue"),

       

    }

]

const router = createRouter({

    history:createWebHashHistory(),

    routes

})


 

export default router

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值