What is the best approach for rectifying my incorrect design?

I have a concern regarding my nuxt.js project

It is known that nuxt.js automatically generates routes.

My page structure looks like this:

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

In the header, there is a navigator which I want to use to switch between pages and change the main content.

However, unlike vue-router, nuxt.js does not have <router-view/>

<route-link></route-link>
<router-view></router-view>

Instead, it only has

<nuxt-link></nuxt-link>

So I designed my code structure like this:

<template>
  <div >

    <Header></Header>   <!-- Main body content goes here -->

    <Footer></Footer>

  </div>
</template>

The Header component:

    <navigator-component></navigator-component>

    <div>
      <Home v-show="$store.state.page_name == 'home' "></Home>
      <Search v-show="$store.state.page_name == 'search' "></Search>
      <Aboutus v-show="$store.state.page_name == 'about_us' "></Aboutus>
      <Contactus v-show="$store.state.page_name == 'contact_us' "> 
      </Contactus>
    </div>

However, there is an issue where the URL does not change, it remains at the root URL.

How can I solve this problem effectively? What changes should I make to the code structure?

Answer №1

Nuxt includes a convenient feature called "router-view", which can be implemented simply with <nuxt />.

The recommended approach is to utilize layouts for organizing your pages.

Within the layouts directory, there is a file named default. This layout is applied to every page by default.

To structure your page content, you can directly edit the default layout file.

Here is an example of how you can set up your default layout:

<template>
  <Header />
  <nuxt />
  <Footer />
</template>

<script lang="ts">
import Vue from 'vue';
import Header from '..';
import Footer from '..';

export default {
  components: {
    Header,
    Footer,
  },
};
</script>

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

Guide to configuring browserify

After installing the modules (browserify, react, reactify), I attempted to process a JSX file using browserify. var React = require("react"); var App = React.createClass({ render: function () { return <h1>111</h1> } }); React ...

Validating inputs in Django with JS/JQuery to ensure accuracy before disabling the submit button

Being new to Django, I am struggling with disabling the submit button until all required fields are filled. Unfortunately, the existing posts like this and this are not providing helpful solutions. Below is my current implementation based on those posts a ...

Is there a discrepancy in performance when running a function on an individual element versus a group of elements within jQuery?

Imagine having the choice between applying a function to an individual DOM element or a list of them: For Individual Elements: $('#element1').click(function () { $(this).hide(); return false; }); $('#element2').click(functi ...

How to style a date and time object using angularjs

What is the best way to convert a PHP datetime object to the format "May-27-1990"? ...

Cascading Style Sheets can be disrupted by Scalable Vector Graphics

Currently, I am incorporating SVG Icons that I created in Illustrator into my Vue.js Webapp. I have utilized Webpack's "require" to load the icons. Rather than accessing the SVGs directly using the src attribute of the img tag, I am inserting them usi ...

Managing responses from ajax requests that can handle both text and json formats

After submitting a form via Ajax and receiving a response from the servlet in either text or JSON format, I'm wondering if there is a way to handle both types of responses. I've read through the jQuery/Ajax documentation, but the JQuery Ajax page ...

Content Mismatch: The webpage was accessed through a secure HTTPS connection, but a request was made for an unsecured resource. Access to this content has been denied as

Error: Mixed Content. The webpage at '' was accessed using HTTPS, but it tried to load an insecure resource ''. This request was blocked as the content needs to be served over a secure connection (HTTPS). ...

Tips for importing and exporting icons in a way that allows for dynamic importing using a string parameter

I am facing an issue with dynamically importing SVG icons in React Native. Initially, I tried using the following code snippet: const icon = require(`@src/assets/icons/${iconName}`) However, after realizing that this approach wouldn't work for me, I ...

Issues with File Upload using Vue.js and the Flask framework

I am encountering difficulties when trying to upload an image using FormData from Vue.js to my Python Flask backend. In my setup, I have a Node.js server that is responsible for handling Vue.js (Nuxt) in order to enable server-side rendering. The basic sta ...

Error 2300 in Vetur: Identical identifier found for '(Missing)'

Recently, I've been encountering a strange issue with Vetur in my typescript nuxt.js project. Every component, whether it's just an empty line or contains code, displays an error message on the first line. I can't pinpoint when this problem ...

Automatically trigger the expansion of all panels within Vuetify using code

I'm attempting to use Vuetify 2.3.5 to programmatically control the opening and closing of expansion panels. <v-expansion-panels accordion> <v-expansion-panel v-for="(item,i) in faqs" :key="i"> <div class ...

Transform Vue.js computed properties into dynamic, reactive elements

My goal is to store the calculated value in my database, but I am facing issues with accessing it using the code snippet below: computed: { total: { get: function() { return this.items.reduce( (acc, item) => acc ...

Switching to a jQuery IF statement instead of a FOR loop allows for more streamlined

I recently made a request to sqlite and am fetching data using the code snippet below: var rows = results.rows; alert(rows.length); for (var index = 0; index < rows.length; index++) { var x = rows.item(index); $( ...

Failed to convert value to a string

I'm dealing with a frustrating issue and I just can't seem to figure it out. The error message I'm getting is Cast to string failed for value "{}" at path "post". { "confirmation": "fail", "message": { "message": "Cast to string fai ...

Creating Custom Filters in Angular using Functions

Attempting to filter ng-repeat using a function instead of an actual filter has presented some challenges. The code snippet below demonstrates the attempt: <tr ng-repeat="(key, value) in dataObj| filter:dataFilter"> The intention is to define dataF ...

Modifying an element's value according to user input: Step-by-step guide

Within my dropdown menu, there is a single option labeled "Others". Upon selecting this option, a textbox appears allowing me to input custom text. Is it possible to dynamically update the value of the <option value="Others">Others</option>, ...

What's causing the error message "button.addEventListener is not a defined function" to appear on my screen?

Could someone shed light on why I'm encountering the error message mentioned above while using this code? It's functioning properly on jsfiddle, but for some reason, it won't execute in the browser. var bladeRunnerButton = document.query ...

What is the best way to transfer scope to a callback function in the context of node-mysql?

When running the code below, I encounter an error that says client is not defined: var mysql = require('mysql'); var conf = { 'database':'database', 'user':'user', 'password':'password ...

Tips on detecting a collision between a cube mesh and the boundaries of a browser using ThreeJS

I'm a beginner in 3D games and ThreeJS. In the image above, my Mesh is located at the left boundary of the browser with a position of -1035 instead of 0. This leads me to question what exactly is the relationship between mesh.position.x in ThreeJS and ...

What is the best method for uploading and saving a file using AngularJS and ExpressJS together?

I am using a library for AngularJS called angular-file-upload. Despite successfully setting it up and getting image uploads to work, I am facing an issue with passing the file to the server side (express js). Jade: input.form-input(ng-model="userAvatarFi ...