Skip to content

Missing named routes throw TypeErrors #1386

@Xcelled

Description

@Xcelled

Version

2.5.2

Reproduction link

http://jsfiddle.net/qkco53b9/1/

Steps to reproduce

Run the example. Look at the console.

What is expected?

Inserting a router link to a named route that doesn't exist should warn.

What is actually happening?

The console spews both warnings about the missing named routes and errors about not being able to access the regex property of a route.


I'm building an SPA and inserting placeholder links to pages I haven't built yet.

It looks like the problem might be here:

const paramNames = record.regex.keys
. Seems the matcher still tries to proceed even if there's no record.

Activity

posva

posva commented on Apr 30, 2017

@posva
Member

I added that label too fast, I was sure there was already a warning 😛

vue-router.js:22 [vue-router] Route with name 'foo' does not exist
Xcelled

Xcelled commented on Apr 30, 2017

@Xcelled
Author

No, you misunderstand @posva. This is a bug, not an improvement. The warning is printed, this is fine. But there is also an error thrown:

image

This issue is about that error, not the warning.

posva

posva commented on Apr 30, 2017

@posva
Member

The error happens because the link is pointing to a non-existent route, that's expected. The warning is there to help you out find the real problem

Xcelled

Xcelled commented on Apr 30, 2017

@Xcelled
Author

That seems unintuitive. I would expect it to warn only (then abort), or at the very least fail gracefully with a specific error message. Instead the error message makes me think there's, well, a bug in the router.

posva

posva commented on Apr 30, 2017

@posva
Member

That's right, I'll create a pr for that. Thanks!

reopened this on Apr 30, 2017
self-assigned this
on Apr 30, 2017
added a commit that references this issue on Apr 30, 2017
8b3cd3d
added a commit that references this issue on Apr 30, 2017
d64af85
added a commit that references this issue on Jun 16, 2017
ed04db8
akoidan

akoidan commented on Jun 19, 2018

@akoidan

Maybe we should consider altering behavior a bit?
For example, when using vue-loader, it could throw compile time error, or at least compile-time warning.

IMHO using named routes should prevent regression in big projects. Atm warnings only pop up if user visits a page with invalid route link. I'm not sure if vue-router has information when it receives RouterConfiguration about all vue components, so maybe it's impossible implement this w/o bundles as webpack.

posva

posva commented on Jun 20, 2018

@posva
Member

You could implement a webpack plugin for it but I think the current behaviour is already easy to detect because of the warnings/errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @posva@akoidan@Xcelled

      Issue actions

        Missing named routes throw TypeErrors · Issue #1386 · vuejs/vue-router