router路由完美demo

本文提供了一个Vue.js路由的详细步骤,从添加依赖到配置各个组件,覆盖了主要的路由设置,适用于多种后端场景。通过这些步骤,你可以创建一个成功的路由处理Demo。
摘要由CSDN通过智能技术生成

完美路由模板

step1: 添加依赖

npm install vue-router
npm install sass-loader

step2: F:\gftproject\vuetify\router\twelve\my-app\src\main.js

import Vue from "vue";
import App from "./App.vue";
import router from "./router/index";
import vuetify from "./plugins/vuetify";
Vue.config.productionTip = false;
new Vue({
   
  router,
  vuetify,
  render: (h) => h(App),
}).$mount("#app");

**step3: F:\gftproject\vuetify\router\twelve\my-app\src\App.vue

<template>
  <div>
    <Notifications />
    <router-view/>
  </div>
</template>
<script>
import Notifications from "@/components/Notifications";
export default {
     
  name: "HelloWorld",
  components: {
     
    Notifications
  },
};
</script>
<style>
</style>

step4: F:\gftproject\vuetify\router\twelve\my-app\src\router\index.js

import Vue from 'vue'
import Router from 'vue-router'
import CabHome from '@/components/Cab/CabHome'
import CabChemical from '@/components/Cab/CabChemical'
import NewsDetail from '@/components/Cab/recomendation/newsDetail'
import News from '@/components/Cab/recomendation/news'
Vue.use(Router)
export default new Router({
   
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
   
      path: '/',
      name: 'newsDetail',
      component: NewsDetail,
    },
    {
   
      path: '/newsDetail',
      name: 'newsDetail',
      component: NewsDetail,
    },
    {
   
      path: '/news',
      name: 'news',
      component: News,
    },
    {
   
      path: '/cabhome',
      name: 'CabHome',
      component: CabHome,
      children: [
        {
   
          path: 'crops',
          component: NewsDetail
        },
        {
   
          path: 'chemical',
          component: CabChemical,
        },
        {
   
          path:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值