question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running into issues with the router and using an external component for the nav

See original GitHub issue

Full source here.

I am receiving the following error by having my navigation menu as an external component:

[Vue warn]: Failed to resolve directive: link (found in anonymous component - use the "name" option for better debugging messages.))

Now after a bit of googling I think it is related to this.

Which is something to do with the component being external.

App.vue:

<template>
  <div id="app">
    <div class="container">
      <navigation></navigation>
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
import Navigation from './components/Navigation'

export default {
  components: {
    Navigation,
  }
}
</script>

Navigation.vue:

<template>
  <div class="navigation">
    <div class="grid -middle">
      <div class="cell -3of12">
        <h1>Otis Wright</h1>
      </div>
      <div class="cell -9of12">
        <ul class="menu">
          <li>
            <a v-link="{ path: 'home' }">Home</a>
          </li>
          <li>
            <a v-link="{ path: '/projects' }">Projects</a>
          </li>
          <li>
            <a href="#">Experiments</a>
          </li>
          <li>
            <a href="#">Contact</a>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

But after looking at the routes I can not figure out what is going wrong?

index.js:

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  mode: 'hash',
  routes: [
    {
      path: '/',
      component: require('../views/Home')
    },
    {
      path: '/projects',
      component: require('../views/Projects')
    }
  ]
})

Sorry still learning Vue and I am probably missing something really simple, the routes are being handled slightly differently to what I am used to so I can’t quite figure it out.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
egoistcommented, Aug 8, 2016

Oh, I misunderstand you.

There’s no v-link directive in vue-router 2

Using a component called <router-link> instead:

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

0reactions
wanteed-lhcommented, Oct 28, 2016

@egoist i try this solution but dosn’t work with that my error [Vue warn]: Failed to resolve directive: link (found in anonymous component - use the “name” option for better debugging messages.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug]: How to navigate outside React context in v6? #8264
Being able to control navigation outside React components is something you just need in some cases. Hooks are great, but we can't use...
Read more >
How to handle navigation in your app with React Router Link
The first two will use the Link and NavLink components, while the last one will make use of the Redirect component. Let's get...
Read more >
You should not use <Link> outside a <Router> - Stack Overflow
This error message is essentially saying that any component that is not a child of our <Router> cannot contain any React Router related ......
Read more >
How To Use Routing with React Navigation in React Native
This library helps solve the problem of navigating between multiple screens and sharing data between them. At the end of this tutorial, you ......
Read more >
React Router DOM: How to handle routing in web apps
Most of the time, you'll use a <Link> component to change the location. <Link>. Let's create a navigation menu. Open src/App.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found