简体   繁体   中英

Disabling v-navigation-drawer on specific routes, Vue-js

I am using a v-navigation-drawer on my webpage, but i want to disable it on specific routes, for example on the landing page. I am currently using the v-navigation-drawer in the App.vue file, as shown:

  <v-app>
<v-navigation-drawer  id ="nav"
  persistent
  :mini-variant="miniVariant"
  :clipped="clipped"
  v-model="drawer"
  enable-resize-watcher
  fixed
  app
  width="275"
  mobile-break-point


>
  <v-list style="width:275px">
    <v-list-tile   style="color: white"
      value="true"
      v-for="(item,i) in items"
      :key="item.path"
      @click="redirect(item.path)"
    >
      <v-list-tile-action style="color:#1872EF" >

   <v-icon v-html="item.icon"></v-icon>
      </v-list-tile-action>

      <v-list-tile-content id="list">
        <v-list-tile-title v-text="item.title"></v-list-tile-title>
      </v-list-tile-content>

    </v-list-tile>
  </v-list>
</v-navigation-drawer>
<v-toolbar
  app
  :clipped-left="clipped" 
  style="background-color:#FFFFFF"
>
  <p style="color:#DFDEE3" > Menu </p>
  <img src="./assets/agilebot.svg" height="44" width="150">
  <v-toolbar-title id="title"></v-toolbar-title>

</v-toolbar>

Which is the best way to disable it in specific routes?

You can do it by using v-if (or even v-show)

<v-navigation-drawer v-if="['home'].indexOf($route.name) === -1">

home being your landing page name in the router:

routes: [
    { path: '/', component: Home, name: "home" }, // names are arbitrary of course

And in array inside v-if just add list of route names where you don't want the drawer shown.

Simple to use with $route it returns current route name in $route.name

<v-navigation-drawer v-if="$route.name!='home'">

In Router

routes: [
    { path: '/', component: Home, name: "home" },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM