How do I use the `route` function in a compiled Vue component?
See original GitHub issueI’m using the following code:
<div class="list-group" v-if="projects.length > 0">
<a v-for="project in projects" :href="route('api.project', {project_id: project.id})" class="list-group-item">{{ project.name }}</a>
</div>
But I get the following error in console:

Note that both route and namedRoutes exist. I have @route above the app.js line in my layout.
Issue Analytics
- State:
- Created 6 years ago
- Comments:27 (9 by maintainers)
Top Results From Across the Web
Getting Started - Vue Router
Define some routes // Each route should map to a component. // We'll talk about nested routes later. const routes = [ {...
Read more >How to use routing in Vue.js ? - GeeksforGeeks
Step 1: Vue Router can be installed through Npm with the package named vue-router using below command. npm install vue-router // OR vue...
Read more >Vue: Automate Your Routing - Medium
In this article, you will learn how to automate your Vue Router route definitions using Node and webpack and without the help of...
Read more >vue.js - VueJS: How to navigate to a different route from global ...
Probably the best approach is to register a hook on the window object and use that so you can navigate from inside Vue....
Read more >How to use routing in Vue.js to create a better user experience
The $router method takes two parameters: first, the name of the component we want to navigate to, and second, the id parameter (or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I know this issue is old, but I came across it by Googling the same problem and thought I might add my solution as well. I was able to add
routeas a global function to all my compiled Vue components by adding this to app.jsAnd then you can call it like so:
@stevebauman Great, thanks. I decided to use a function instead as that appears to work OK:
…
Indeed, it would be nice to be able to use this the other way, though. I can keep this issue open as a feature request or I can close it. I’m happy that I have a solution now.