简体   繁体   English

Vue-Router仅适用于某些路线

[英]Vue-Router only works on some routes

My vue-router routes the URL on all menu buttons correctly, but does not show each Vue component properly. 我的Vue路由器正确路由了所有菜单按钮上的URL,但是没有正确显示每个Vue组件。 A demonstration can be found here . 这里可以找到一个示范。

Inside of my HTML (I am using Vuefy) 在我的HTML内部(我正在使用Vuefy)

<div class="navbar-start">
        <a class="navbar-item">
          <router-link to="/" class="router-link">  // <-- THIS WORKS
          Home
        </router-link>
        </a>
        <a class="navbar-item">
          <router-link to="/items" class="router-link">  // <-- THIS WORKS
          My Products
        </router-link>
        </a>
      <div class="navbar-item has-dropdown is-hoverable">
          <a class="navbar-link">
            <router-link to="/information" class="router-link">  // <-- DOES NOT WORK
            Info
            </router-link>
          </a>
        <div class="navbar-dropdown is-boxed">
          <a class="navbar-item">
            <router-link to="/about" class="router-link">  // <-- THIS WORKS
            About
            </router-link>
          </a>
          <a class="navbar-item">
            <router-link to="/terms" class="router-link">  // <-- DOES NOT WORK
            Terms
          </router-link>
          </a>
        </div>
      </div>
    </div>

My router.js file is set up the following: 我的router.js文件设置如下:

import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/about',
      name: 'about',
      component: () => import('./views/About.vue')
    },
    {
      path: '/new',
      name: 'create-item',
      component: () => import('./views/CreateItem.vue')
    },
    {
      path: '/',
      name: 'home',
      component: Home
    },
    {
      path: '/items',
      name: 'my-items',
      component: () => import('./views/MyItems.vue')
    },
    {
      path: '/signin',
      name: 'sign-in',
      components: () => import('./views/SignIn.vue')
    },
    {
      path: '/terms',
      name: 'terms',
      components: () => import('./views/Terms.vue')
    },
    {
      path: '/information',
      name: 'info',
      components: () => import('./views/Info.vue')
    }
  ]
})

Additionally, my App.vue file shows the router-view properly, along with the menu. 另外,我的App.vue文件正确显示了路由器视图以及菜单。

<template>
  <div id="app">
    <div id="nav">
      <Menu/>
    </div>
    <router-view/>
  </div>
</template>

<script type="text/javascript">
    import Menu from '@/components/Menu.vue'

    export default {
      components: {
        Menu
      }
    }
</script>

The following is a photograph of my navigation. 以下是我的导航照片。 To repeat, clicking on 'info' and 'terms' (submenu of info) do not load their respective Vue components, but does change the URL. 重复一遍,单击“ info”和“ terms”(info的子菜单)不会加载它们各自的Vue组件,但是更改URL。 在此处输入图片说明

I triple-checked my syntax and checked the documentation, but could not seem to find my error. 我仔细检查了我的语法并检查了文档,但似乎找不到我的错误。 The platform at which my code is hosted at can be found here . 可以在此处找到托管我的代码的平台。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks, Edwin. 谢谢,埃德温。

I found the error. 我发现了错误。 I spelled 'component' instead of 'components' several times in my routes.js file. 我在routes.js文件中多次拼写“ component”而不是“ components”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM