0
votes

Router not working properly. It looks like working

App running at:

  • Local: http://localhost:8080/

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";`
        }
      }
    }
  };
1
please provide a meaningful titleBoussadjra Brahim
You have to include some more details in this question. like, what is the problem? What do you expect and what happens instead ...?Sølve Tornøe
My component Web not displayed "Hello" in my path: '/web', ..there displayed my 'App' insteadJustin Moreyl
<template> <div id="app"> <div class="container"> <!-- <div id="nav"> <router-link to="/">Web</router-link> <router-link to="/about">About</router-link> </div> --> <Header/> <div class="content"> <Navbar/> <Home/> </div> </div> <router-view/> --> </div> </template> <script> import Home from '../src/views/Home.vue' import Header from '../src/views/Header.vue' import Navbar from '../src/views/Navbar.vue' export default { name: 'App', components: { Header, Navbar, Home }Justin Moreyl
@JustinMoreyl did you try out my answer?Boussadjra Brahim

1 Answers

1
votes

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