Guide on positioning components to the right side of the NavigationDrawer in Vuetify with VueRouter

Working on my VueJS project, I've implemented a system to display content based on the user login using Firebase and Vuex state management. When a user is logged in, the content is shown using the v-if directive. Currently, I have successfully placed the NavigationDrawer in the correct position but am facing issues displaying the components accordingly. My objective is to have a fixed NavigationDrawer on the left side and the pages (components) on the right, with navigation handled by VueRouter.

The current layout can be viewed here:

https://i.sstatic.net/vHTBE.png

App.vue

<template>
  <v-app>
    <v-content v-if="isLoggedIn">
      <v-navigation-drawer v-if="isLoggedIn" permanent>
        <v-toolbar flat>
          <v-list>
            <v-list-tile>
              <v-list-tile-title class="title">Application</v-list-tile-title>
            </v-list-tile>
          </v-list>
        </v-toolbar>

        <v-divider></v-divider>

        <v-list dense nav>
          <v-list-item v-for="item in items" :key="item.title" link>
            <v-list-tile>
              <v-list-tile-action>
                <v-icon>{{item.icon}}</v-icon>
              </v-list-tile-action>

              <v-list-tile-content>
                <v-list-tile-title>{{item.title}}</v-list-tile-title>
              </v-list-tile-content>
            </v-list-tile>
          </v-list-item>
        </v-list>
      </v-navigation-drawer>
    </v-content>

    <login v-else />
  </v-app>
</template>

<script>
import login from "@/views/Login";

export default {
  name: "App",
  components: {
    login
  },
  data() {
    return {
      items: [
        { title: "Dashboard", icon: "dashboard" },
        { title: "Settings", icon: "settings" }
      ]
    };
  },
  computed: {
    isLoggedIn() {
      return this.$store.getters.user != null;
    }
  }
};
</script>

router/index.js

import Login from '@/views/Login'
import Dashboard from '@/views/Dashboard'
import Settings from '@/views/Settings'

import VueRouter from 'vue-router'
import Vue from 'vue'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'Login',
        component: Login
    },
    {
        path: '/Settings',
        name: 'Settings',
        component: Settings
    },
    {
        path: '/Dashboard',
        name: 'Dashboard',
        component: Dashboard
    }
]

export default new VueRouter({
    mode: 'history',
    routes
})

Settings.vue

<template>
  <h1>Settings</h1>
</template>

<script>
export default {
  name: "Settings"
};
</script>

Dashboard.vue

<template>
  <h1>Dashboard</h1>
</template>

<script>
export default {
  name: "Dashboard"
};
</script>

<style>
</style>

Answer №1

If you want to display the Login component, consider placing router-view in App.vue

<template>
  <v-app>
    <v-navigation-drawer v-if="isLoggedIn">
      ...
    </v-navigation-drawer>
    <v-content>
      <router-view></router-view>
    </v-content>
  </v-app>
</template>

<script>
export default {
  mounted () {
    if (this.isLoggedIn) {
      // It is recommended to use router guards
      // https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards
      this.$router.push('/login')
    }
  },
}
</script>

Please keep in mind:

  • Avoid importing Login into App.vue. Utilize router-view to render it instead.
  • For better organization, implement router guards in a separate location like router/index.js. You can refer to an example here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can someone confirm if a user has administrator privileges?

Is it feasible to determine if members of a discord server possess administrator privileges in a looping structure? I am aiming to prohibit individuals who hold a role below my bot in the server that belongs to me and my companions. How can I achieve this? ...

Utilize MaterialUI Grid to define custom styles for the ::after pseudo-element

I came across a helpful article on Stack Overflow about Flex-box and how to align the last row to the grid. I'm interested in implementing it in my project: .grid::after { content: ""; flex: auto; } However, I'm not sure how to inc ...

Ways to showcase a JavaScript popup on an Android WebView

Can a JavaScript popup window be opened on an Android web viewer that is coded similarly to this example from Google? If so, how can this be accomplished without closing the original background page and ensuring it resembles a popup as shown in the picture ...

Implementing Formik in React for automatic updates to a Material-UI TextField when blurred

Presently, I am developing a dynamic table where users can simultaneously modify multiple user details in bulk (Refer to the Image). The implementation involves utilizing Material-UI's <TextField/> component along with Formik for managing form s ...

Iterating through a for loop in Angular2 to send multiple GET requests to a Django backend

Currently, I'm facing a challenge with performing multiple GET requests using Angular2 within a Django/Python environment. After successfully making an API request and retrieving a list of users to determine the current user's ID, I utilize a .f ...

Incorporate a vertical scrollbar in the tbody while keeping the thead fixed for smooth vertical scrolling

I'm seeking a solution to implement horizontal and vertical scroll for my table. Currently, the horizontal scroll is working fine, but when trying to add vertical scroll, the table header also moves along with it. Is there a way to keep the table hea ...

Getting rid of quotes in a JSON result

My unique code snippet Retrieve data = Array[2] : 0:object id : "1" lat : "76.23" long:"21.92" 1:object id:"2" lat:"10.23" long:"12.92" var newCoords=[]; for(_i = 0; _i < ...

The form yields no response and fails to send any data

Ensuring that the form on this site successfully sends the name and phone number is crucial. However, upon clicking the send button, I encounter an empty modal window instead of a response indicating whether the data was sent or not. The contents of the fi ...

Navigate to a particular section in the webpage

There are a few div elements with the class .posts that each have an attribute data-id which corresponds to the ID in a MySQL database. <div class="posts" data-id="1"></div> <div class="posts" data-id="2"></div> If I want to scrol ...

What is the best way to ensure that a child div can expand to fit within the scrollable area of its parent div

I am facing an issue with a parent div that changes size based on the content inside it. When the content exceeds the initial size, causing the parent to scroll instead of expanding, I have a child div set to 100% width and height of the parent. However, t ...

Changing from localhost:3000/admin to localhost:3000 within the local server

I am currently developing a node.js application. My goal is to have the homepage rendered after the admin successfully uploads data, transitioning from localhost:3000/admin to localhost:3000. I attempted to achieve this using the code snippet below: route ...

Click to expand for answers to commonly asked questions

Having trouble setting up a FAQs page on my blog and can't seem to get the code right. Check out what I'm trying to do here: http://jsfiddle.net/qwL33/ Everything seems fine but when I click on the first question, both questions open up. Can som ...

Tips on identifying HTML email input validation using JavaScript?

Just like when you can determine whether an input element with a required attribute was successfully validated, try using the following code: if($('input[type="email"]').val() && $('input[type="email"]').val().includes('@') & ...

Display error messages in Vue.js

Within this component, I have a method that updates an employee. My goal is to display the error message in the view immediately after the "errorMessage" variable is assigned/changed within the "error" callback of the ajax call. var EmployeeEdit = Vue ...

How come this constant can be accessed before it has even been declared?

I find it fascinating that I can use this constant even before declaring it. The code below is functioning perfectly: import { relations } from 'drizzle-orm' import { index, integer, pgTable, serial, uniqueIndex, varchar } from 'drizzle-orm ...

Finding the perfect pairing: How to align counters with objects?

public counter = 0; x0: any; x1: any; x2: any; x3: any; x4: any; next(){ this.counter += 1; this.storage.set("Count", this.counter); console.log(this.counter); this.logic(); } logic(){ //automatic counter here var xNum = JSON.parse(JSON.stri ...

Combining Laravel with Vue: Organizing Routes in web.php and api.php Files

Hey there, I'm relatively new to Laravel and currently working on a project. I would really appreciate some advice on choosing the right architecture. My approach involves utilizing Vue for the front end and Laravel for the back end. Currently, I am ...

What can you tell me about Page Event functionality in Datatables?

Curious question -- I'm currently seeking a practical example of how to implement a 'page' event in a project utilizing DataTables. The provided documentation can be found here -- http://datatables.net/docs/DataTables/1.9.4/#page. Despite t ...

Executing a JavaScript Function in the Background using Cordova

Despite the numerous questions and plugins available on this topic, finding a solution has proven to be elusive for me. The most highly recommended plugin for this issue can be found here. My goal is to run MyService in the background, subscribe to the ON ...

What is the best way to ensure NPM package manager points to my custom version of a library?

Looking to address a bug in an NPM library. Seeking guidance on configuring my software to point to my customized version of the library using package.json instead of the generic version from npmjs.org. This way, I can effectively debug my own iteration o ...