Vue router displays a white screen instead of content

I have been working on a web application using vue.js for my frontend. I have set up my router, but for some reason, the pages are not rendering. I have double-checked everything and there are no errors in my code. Here is a snippet of what I have:

App.vue

<template>
    <div>
        <router-view></router-view>
    </div>
    </template>
    <script>
    export default {
        name: 'App'
    }
    </script>

    

Router.js

import Vue    from 'vue'
    import Router from 'vue-router'
    import Home    from './components/Home'
    import Table   from './components/Table'

    Vue.use(Router)

    export default new Router({
        routes: [
            {
                path: '/',
                component: Home
            },
            {
                path: '/table',
                component: Table
            },
        ],
        linkActiveClass: "active",
        mode: "hash"
    })
    

main.js

import Vue from 'vue'
    import App from './App'
    import router from './router'

    Vue.config.productionTip = false

    new Vue({
        el: '#app',
        router,
        components: { App },
        template: '<App/>'
    }) 
    

For example, here is Home.vue

<template>
    <div class="flex flex-wrap -m-3">
        <h1>You're looking at your home</h1>
    </div>
    </template>

    <script>
    export default {
        name: 'Home',
        data () {
            return {}
        }
    };
    </script>
    

If anyone can provide some guidance or assistance, it would be much appreciated.

Answer №1

The code in your sandbox may not match exactly with the code provided in the answer, which could be causing the discrepancy. However, rest assured that everything is functioning correctly.

To view the table page in your sandbox, simply insert the li tag within one of the ul tags in your sandbox home component:

<li>
  <a
    href="#/table"
  >table</a>
</li>

Alternatively, you can use the following code:

<router-link to="table">Go to Table</router-link>

Don't forget to add the following code to your Table.vue component to navigate back:

<router-link to="/">Go to Home</router-link>

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

Displaying pictures under specific conditions

I've recently completed the coding and CSS for my website after working on it for quite some time. Now, I want to enhance it by incorporating new features. The website is fully operational and generates revenue primarily through Google AdSense. I am i ...

Leverage the power of the modal component in your ReactJS

I'm facing an issue with the antd library. Even after installing it from the official site and importing the modal component, it's not functioning properly for me. I've carefully checked everything in my code and everything seems to be fine. ...

What is the best way to extract the body content from a Markdown file that includes Frontmatter

How can I retrieve the content of the body from my markdown file using front matter? Currently, it is displaying as undefined. What steps should I take to fix this issue? {latest.map(({ url, frontmatter }) => ( <PostCard url={url} content={frontmat ...

Troubleshooting issue with Vue loader and AWS Amplify compilation error

I encountered an error when running vue-cli-service build and I am unsure about the missing component. Running NODE_ENV=development vue-cli-service build --mode development --watch The following relative module was not found: * ./models in ./node_modul ...

Storing JSON location data in JavaScript

When converting JSON data into a list structure, I aim to use the "AAA.BBB[0].CCC.DDD[5].EEE" format as the ID. This way, any modifications made by a user to the content of that specific list item will directly affect the JSON data linked to that location. ...

AngularJS - ng-change does not trigger for checkbox that toggles the class "switch"

CSS Styling: <span style="color: blue;">Hello, World!</span> JavaScript Function: function showMessage(){ alert('Hello!'); } I tried to implement a span element with blue text color. However, the function that was supposed to ...

JavaScript allows for selecting individual IDs by their corresponding numbers

Looking to retrieve numerical IDs <div class="user-view"> <div class="show_user_div"> <div class="disp"> <a href="/profile/name1/">name1</a><br /> <span id="show_a_3"> <a id="ref_show(3)">Show Details</ ...

Create dynamic automatic titles in HTML with JavaScript

Below is the code snippet to add an image with a link to the home-page and an h1 with the document name (if there isn't one already). This HTML code includes a JavaScript file reference in the <head> section and uses a <h1> tag for the ti ...

Working with NodeJS: Utilizing object casting with default values and eliminating superfluous

In the backend code of a NodeJS application, there is an object defined as follows: { name : "foo" secret : "bar" } The objective is to return this object as JSON in response to an HTTP request without including the secret key. The desired return obj ...

When switching from JavaScript to jQuery, the button values become invisible

Currently, I have a functional app that can dynamically change the values of buttons based on user input. The current implementation is in vanilla JavaScript within the script.js file. However, I am looking to enhance the functionality and user experience ...

Unusual div image alignment when dimensions are dynamically adjusted with Javascript animations

I have created a basic webpage using JavaScript that aims to scale an element from the center of the page over time when clicked. It is functioning properly for the SVG element I tested it with. However, when I use an image, it initially appears outside o ...

employ the value of one array in a different array

Currently, I am working with an array (const second) that is being used in a select element to display numbers as dropdown options {option.target}. My question is: Is there a way to check within this map (that I'm using) if the 'target' from ...

Step-by-step guide on removing the focusin event listener from a Bootstrap 5 modal

My current app has a legacy modal that uses a kendo dropdown list element bound to an ajax call with filtering. I'm trying to avoid rewriting this component if possible. However, there is an issue where when the modal opens and you focus on the dropdo ...

Modify the class of the dropdown and heading 2 elements if they meet specific conditions using Animate.css

Is it possible to add a class using jQuery when two specific conditions are met? 1) If the dropdown selection is either "acting" or "backstage" 2) If the membership status is set to "Non-member" If both of these requirements are fulfilled, I would like ...

Verify the dates in various formats

I need to create a function that compares two different models. One model is from the initial state of a form, retrieved from a backend service as a date object. The other model is after conversion in the front end. function findDateDifferences(obj1, ...

The Access-Control-Allow-Headers Error prohibits the use of the Authorization request header field

I am currently working on integrating a VueJS frontend application with an ExpressJS backend server. In my server code, I have implemented the following: var allowCrossDomain = function(req, res, next) { res.header('Access-Control-Allow-Origin&ap ...

Can someone provide a description for a field within typedoc documentation?

Here is the code snippet: /** * Description of the class */ export class SomeClass { /** * Description of the field */ message: string; } I have tested it on the TSDoc playground and noticed that there is a summary for the class, but not for it ...

Adjusting height in Google Maps to fill the remaining space

Currently, I am developing a map application where I want the Google Maps DIV to occupy the remaining height under the header. Here is the code snippet: <!DOCTYPE html> <head> <title>Map Application</title> <style type ...

You will still find the information added with JQuery append() even after performing a hard refresh

After making an Ajax call using JQuery and appending the returned information to a div with div.append(), I encountered a strange issue. Despite trying multiple hard refreshes in various browsers, the appended information from the previous call remained vi ...

What is the standard approach for exchanging localized user interface strings between Microsoft's MVC and JavaScript?

In the process of developing an application that utilizes a dynamic, javascript-based client, I am facing the need for localization. This particular application includes significant UI components that are not generated by Javascript and are instead served ...