Justin Moreyl
Justin Moreyl

Reputation: 109

Vue-router doesn't show a component when visiting the correspondent path

Router not working properly. It looks like working

App running at:

But it seems router can't see the component ((

My Router

import Vue from 'vue'
import VueRouter from 'vue-router'
import Web from '@/views/Web.vue'


Vue.use(VueRouter)

  const routes = [
  {
    path: '/web',
    name: 'Web',
    component: Web
  },

  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/About.vue')
    }

  }
]

const router = new VueRouter({
  routes
})

export default router

My Component:

<template>
    <h1>Hello</h1>
</template>

<script>

export default {
    name: 'Web'
}
</script>

My Error:

 App running at:
  - Local:   http://localhost:8080/

But there are nothing happens (

What it can it be ?

May be I need some dependencies in my package.json ?

{
  "name": "osprey",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve ",
    "build": "vue-cli-service build"
  },
  "dependencies": {
    "autoprefixer": "^9.8.6",
    "live-server": "^1.2.1",
    "vue": "^2.6.11",
    "vue-router": "^3.2.0",
    "vuex": "^3.4.0"
  },
  "devDependencies": {
    "@vue/cli-plugin-router": "~4.4.0",
    "@vue/cli-plugin-vuex": "~4.4.0",
    "@vue/cli-service": "~4.4.0",
    "node-sass": "^4.9.0",
    "sass-loader": "^7.0.1",
    "vue-template-compiler": "^2.5.17"
  }
}

or something in my vue.config.json ?

module.exports = {
    css: {
      loaderOptions: {
        sass: {
          data: `@import "@/styles/_variables.scss";`
        }
      }
    }
  };

Upvotes: 0

Views: 543

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

Add the mode history to your router config as follows :

const router = new VueRouter({
 mode:'history',
  routes
})

in order to access to your paths like /web, but in your case you have to use #/web since the default mode is hash

Upvotes: 1

Related Questions