A guide on implementing header and sidebar rendering post login with Vue

In my Vue.js application, I am currently rendering it using different pages. A problem I'm facing is that when I log in for the first time, it only renders the main component of the page according to vue router. I want the login function to execute and then redirect to /dashboard. However, I need a way to reload my App.vue file or somehow refresh the header and sidebar in the following code. Currently, the header and sidebar are not displayed when on /login, so using router.push('/dashboard') leads to everything except the header and sidebar being rendered.

<Header />
<Sidebar v-if="!pageOptions.pageWithoutSidebar" />
<div id="content" class="content" v-bind:class="{ 'content-full-width': pageOptions.pageContentFullWidth, 'content-inverse-mode': pageOptions.pageContentInverseMode }">
    <router-view></router-view>
</div>

Answer №1

If you want to display your page after logging in with a parent container, follow this structure:

const routes = [
  {
    path: '/',
    component: () => import('layouts/MyLayout.vue'),
    children: [ // ALL ROUTES AFTER LOGIN
      { path: '', component: () => import('pages/Index.vue') }
    ]
  }
]

In the MyLayout.vue file, you can include your header and sidebar components.

Your MyLayout.vue should look like this:

<template>
  <div>
    <Header></Header>
    <SideBar></SideBar>
    <section>
        <router-view>
        </router-view>
    </section>

  </div>
</template>

<script>

import Header from '../layouts/Header.vue'
import SideBar from '../layouts/Sidebar.vue'

....

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

Slide the navbar and bottom toolbar up or down when scrolling, similar to the Pinterest app's functionality

Similar to the functionality in the Pinterest app, I want my top navigation bar to slide up/down and at the same time have my bottom toolbar slide down/up when scrolling. While I've successfully made my top navigation bar hide/show using the code pro ...

Leveraging React Native to retrieve information from a promise in JSON format

After successfully fetching the JSON data, I now have an array. My question is how can I utilize the elements within this array in a React Native environment? Below is my current approach: export default function display() { const fetching = async() => ...

"Utilizing the ajaxcontroltoolkit CascadingDropDown feature to trigger a method once the control

On my webpage, I am using a CascadingDropDown control and I am looking to trigger some jQuery actions once the dropdown is populated. As per the guidance provided in the documentation, there is an event called (populated) that can be used for this purpose. ...

Skipping code in JavaScript/jQuery function on window load

I have created a function that applies specific CSS rules to elements when the window is fully loaded. Check out my code below: function applyHover() { $('.view_preloader .overlay').css('opacity',1); $('.view_pre ...

AngularJS Service Implementing the Pub/Sub Design Pattern

I've been browsing for solutions to a problem and stumbled upon an answer provided by Mark Rajcok angular JS - communicate between non-dependend services However, I am struggling to fully grasp his explanation, particularly this part: angular.forEa ...

React-router: Issue with ProtectedRoute authentication mechanism not functioning as expected

I'm currently working on setting up protected routes that can only be accessed after the user has logged in. There are two main routes to consider: /login, which is the Login component (public), and /, which is the Dashboard component (protected). Wh ...

Adding non-reactive elements to reactive ones in VueORCombining static and dynamic components in

I am currently working on a project where I have a parent component called <v-window> that contains children elements of type <v-window-item>. The first child item is responsible for looping through data fetched from a Vuex getter and dynamical ...

Troubleshooting Vee-validate scope issues in Nuxt.js and Vuetify

I'm experiencing an issue with validation using vee-validate and Vuetify: I have two forms with different scopes, both being submitted within one function. While the validation is functioning correctly upon submission, the input errors are not displa ...

Exploring the World of Html

I'm struggling with an HTML problem related to a web programming class I'm taking. The assignment involves creating a video game using HTML and JavaScript, where an image moves randomly on the screen and the player must click on it as many times ...

`Cannot press when using custom cursor in JS?`

Hey there! I'm currently working on implementing a custom cursor for specific elements on my website. However, I've encountered a little hiccup - once the custom cursor is in place, I'm no longer able to click on any elements. Does anyone ha ...

Rollup.js with Vue.js displays an HTML comment instead of rendering Vue HTML content

As I delve into the world of Vue.js, I am encountering some challenges with rendering a simple interpolation within my local development application. The Issue Strangely, the Vue instance displays an HTML comment of createElement <body> <sc ...

Events triggered when a Jquery checkbox is toggled between checked and unchecked

I have written some HTML code that utilizes jQuery to manage checkboxes. <tr> <td> <div class="checkbox"> <label><input type="checkbox" id="checkbox2"></label> </div> </td> & ...

Verifying the Redux saga test plan's functionality by testing a reducer with a specific state branch

I'm facing some challenges in properly testing my saga. The issue arises because when the saga is running, the reducer is mounted at state: {...initialState}, while my saga select effects expect the reducer to be mounted at state: {authentication: {.. ...

The Ionic application functions flawlessly on the browser, but unfortunately, it is not performing well on my Android device

My ionic application works well in Chrome, but after generating the .apk file, it encounters issues. In Chrome's developer mode, there is a warning: SVG's SMIL animations (<animate>, <set>, etc.) are deprecated and will be removed. P ...

Unexpected Results when Sorting Objects by Value

When attempting to organize 2 objects based on the value of first_name, one in ascending alphabetical order and the other in descending order, both end up being sorted in descending order. What could be the mistake in this code? The objective is to rearr ...

Do not attempt to log after tests have finished. Could it be that you overlooked waiting for an asynchronous task in your test?

Currently, I am utilizing jest in conjunction with the Vue framework to create unit tests. My test example is successfully passing, however, I am encountering an issue with logging the request. How can I resolve this error? Is there a mistake in my usage o ...

The captivating logo animation of Google Chrome

For optimal viewing experience, it is recommended to use Chrome or any WebKit browser. https://www.google.com/intl/en/chrome/browser/ Hovering over the chrome logo reveals an amazing effect. I tried downloading the page source, but got lost in it. The s ...

Stop unauthorized content injections in HTTP request headers

Utilizing the Requestly Chrome extension, I am able to intercept and manipulate HTTP request headers within my NodeJS application. https://i.sstatic.net/yxa2J.png What measures can I take to prevent attacks? For instance, changing the Referer header and i ...

Tips for testing a service in Angular using unit testing techniques

Within my service, I have a function that looks like this: exportPayGapDetails(filterObject: PayGapDetailFilter): void { const url = `${this.payGapDetailExportUrls[filterObject.type]}`; this.http .post<PollInitResponse>( `/adpi/rest/v2/s ...

Troubleshooting the onExited callback issue with Popover component in Material UI

<Popover key={element.name} classes={{ paper: classes.paper }} open={open} anchorEl={this.myRef.current} anchorOrigin={{ vertical: ' ...