What is the best way to show a specific page using router-view?

Is it possible to restrict router-view to display content from only one specific page?

App.vue

<div id="app">
  <div class="out-page" v-if="$route.path === '/login'">
    <router-view name="login"></router-view>
  </div>
  <div class="register-page" v-if="$route.path === '/register'">
    <div class="register-wrapper">
      <router-view name="register"></router-view>
    </div>
  </div>
  <div class="in-page" v-if="$route.path === '/home'">
    <div class="home-container>
      <router-view name="home"></router-view>
    </div>
  </div>
</div>

router.js

export default new Router({
  mode: "history",
  routes: [
    {
      path: "/login",
      name: "login",
      component: () =>
        import(/* webpackChunkName: "Login" */ "./pages/login.vue")
    },
    {
      path: "/register",
      name: "register",
      component: () =>
        import(/* webpackChunkName: "Register" */ "./pages/register.vue")
    },
    {
      path: "/home",
      name: "home",
      component: () =>
        import(/* webpackChunkName: "Home" */ "./pages/home.vue")
    }
  ]
});

Is there a way for the router-view to exclusively show content from just one specific page and not all of them, even when using the name attribute?

Any suggestions on how to achieve this?

Answer №1

It seems like the goal of your code is a bit unclear at the moment. Typically, if you have just one view on a page, the structure of the app would resemble something along these lines:

  <div id="app">
    <div class="shared-outer-class">
      <router-view/>
    </div>
  </div>

Customizations for each view would be handled within their individual components or through a shared outer component as needed.

If your intention is to incorporate multiple views on the same page, then named views can be utilized. However, based on your example, it doesn't seem like that's what you're trying to achieve.

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

Tips for transforming Laravel database information into a compatible JSON format for seamless integration with vuejs

In Laravel, attribute names for modals use underscores (_) like: first_name On the other hand, attribute names for JavaScript objects use camelCase: { firstName: "..." } This difference can cause conflicts. Is there a way to resolve it? ...

Fixing the problem of digest overflow in AngularJS

I've been working on a code to display a random number in my view, but I keep encountering the following error message: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! It seems to be related to a digest outflow issue, and I&apo ...

Sleek Dialog Boxes with Bootstrap 4 - Bootbox Modal

Within the structure of my webpage, there resides a table containing various elements. One specific cell within this table holds a link that triggers jQuery scripts upon being clicked. An example action initiated by clicking this link is displaying a Boots ...

I want to know how to move data (variables) between different HTML pages. I am currently implementing this using HTML and the Django framework

I am currently working on a code where I am fetching elements from a database and displaying them using a loop. When the user clicks on the buy button, I need to pass the specific product ID to another page. How can I retrieve the product ID and successful ...

How to maintain the focus within a jQuery dialog box

Exploring the world of jQuery dialog, I'm eager to incorporate it into my latest side project. My goal is to enhance accessibility by adding tabindex to the divs within the dialog for easy tab navigation. However, I encountered an issue where the focu ...

Steps for integrating a valid SSL certificate into a Reactjs application

After completing my ReactJS app for my website, I am now ready to launch it in production mode. The only hurdle I face is getting it to work under https mode. This app was developed using create-react-app in a local environment and has since been deployed ...

Frequent running of jQuery scripts

In my jQuery ajax code, I created a FitnessPlanDay: // Add Day ajax $('#addDay').on("click", function() { $.ajax({ url: '@Url.Action("AddDay")', type: 'POST', ...

Disable automatic matrix updates for all meshes in the 3D scene using Three.js

In my current project, I am working with a scene that includes multiple OBJ meshes and I am looking to deactivate matrixAutoUpdate for all of them. These OBJ objects are comprised of numerous child meshes, making it challenging for me to figure out how t ...

What is the best approach to creating customizable modules in Angular2?

I'm exploring the most effective approach to configuring modules in Angular 2. In Angular 1, this was typically achieved through providers. As providers have been altered significantly, what is the preferred method for passing configuration parameters ...

Ways to present a pop-up dialog box featuring word corrections

I have developed a word correction extension that encloses the incorrect word in a span element. Upon hovering over the word, a drop-down menu with possible corrections should be displayed. However, my current code is not functioning properly. How can I en ...

Strange black backdrop in dialog component

Today I came across a rather peculiar issue and was wondering if anyone else had experienced it and found a solution. The problem is pretty straightforward - when I load up my Vue component with a dialog element from the Element-UI library, the background ...

Determine the total of all input values

My challenge is to calculate the total sum of all inputs, with the twist that they are hidden initially and randomly revealed by visitors. Imagine there are 30 inputs in total. So far, I have successfully identified the revealed inputs without the "hidden ...

Discovering the worth of an array property in JavaScript

I have a custom script that generates and outputs a JSON formatted object: function test() { autoscaling.describeAutoScalingGroups(params, function(err, data) { if (err) console.log(err, err.stack); // an error occurred else console.lo ...

How to implement a scrollbar for tables using Angular

How can I implement a vertical scroll bar only for the table body in my Angular code? I want the scroll bar to exclude the header rows. Since all rows are generated by ng-repeat, I am unsure how to add overflow style specifically for the table body. Here ...

Removing data with sweetalert in a Ruby on Rails application

Hey there, I'm currently exploring the use of sweet alert js to enhance the appearance of my alert boxes. In my table, I have a specific data deletion feature that is triggered by a standard JavaScript alert confirmation. However, when attempting to i ...

What is the best way to establish a connection between a client and MongoDB

My attempt to connect my client with MongoDB resulted in an error message: MongoParseError: option useunifedtopology is not supported. I am unsure of the reason behind this issue and would greatly appreciate your assistance. Below is the snippet of code ...

Can React.js be seamlessly integrated with Apache Wicket?

I have an older web application built with Apache Wicket and I'm interested in exploring the option of adding a new feature using React.js. Can this be done? I've begun looking into it, but haven't come across any helpful resources yet. Cu ...

Top Strategies for PHP - Managing Directs and Header Content

PHP is a versatile language frequently used for generating 'templates' like headers to maintain a consistent look across websites and simplify updates via require or include commands. Another common task involves managing log-ins and redirecting ...

Can you embed a VueJs Component using jquery?

I have a complex application where I previously utilized jQuery to dynamically change views: $(function(){ $(".changeview").bind("click",function(){ $.post(linkAction,phpData,function(data){ $('#loa ...

Attempting to include a select element via transclusion

Looking to develop a custom directive named select that will replace a select element with a customized dropdown interface. For a clear example, check out this jsfiddle where the concept is demonstrated. Let's consider the below select element: < ...