Skip to content

Missing named routes throw TypeErrors #1386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Xcelled opened this issue Apr 30, 2017 · 7 comments
Closed

Missing named routes throw TypeErrors #1386

Xcelled opened this issue Apr 30, 2017 · 7 comments
Assignees

Comments

@Xcelled
Copy link

Xcelled commented Apr 30, 2017

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.

@posva
Copy link
Member

posva commented Apr 30, 2017

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

@posva posva closed this as completed Apr 30, 2017
@Xcelled
Copy link
Author

Xcelled commented Apr 30, 2017

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
Copy link
Member

posva commented Apr 30, 2017

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
Copy link
Author

Xcelled commented Apr 30, 2017

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
Copy link
Member

posva commented Apr 30, 2017

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

@posva posva reopened this Apr 30, 2017
@posva posva self-assigned this Apr 30, 2017
posva added a commit that referenced this issue Apr 30, 2017
posva added a commit that referenced this issue Apr 30, 2017
yyx990803 pushed a commit that referenced this issue Jun 16, 2017
* Prevent unecessary Exception with non-existent links

Closes #1386

* Remove semis

* Keep same behaviour in dev and pro with non-exsistent links
@akoidan
Copy link

akoidan commented Jun 19, 2018

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
Copy link
Member

posva commented Jun 20, 2018

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
Projects
None yet
Development

No branches or pull requests

3 participants