baseprime / grapnel

The smallest JavaScript router with named parameters, HTML5 pushState, and middleware support
http://grapnel.js.org
468 stars 40 forks source link

0.7 has broken pattern matching #74

Closed Javiani closed 5 years ago

Javiani commented 6 years ago

Hi! First of all, keep up with this awesome library! I'm using as part of my own framework and its the best router I've ever found for javascript.

However, yesterday I have a little headache, I had to npm install it for a new project, but I got the 0.7 version which is not working as expected, I coudn't match any of my routes using router.get() ( using hash ), before I go crazy I compared the new project to a older one then I realized that was a version issue. So I forced the npm version to 0.6 and it worked like a charm.

I don't know if something changed and documentation is not updated or something like that, I'm just warning you that the library is currently broken in 0.7 version.

Bye! o/

baseprime commented 6 years ago

Hi @Javiani, thanks! Could you give a code example of how you’re using Grapnel? Are you using Webpack or including it using <script> tag?

Javiani commented 6 years ago

Hi @baseprime !

I'm using Webpack, and the url is : http://localhost:3000/playlists/#/advisor/clark-kent

I'm trying to get advisor name by using :

const router = new Grapnel()
router.get('/advisor/:analyst', console.log)

console.log is not being called for that route. It only works on 0.6 version.

Thanks!

baseprime commented 6 years ago

Are you loading window as an external in your webpack config?

Check out this GutHub Issue for more info

Javiani commented 6 years ago

Hi @baseprime , I tried to do that, but it still don't work. One thing I notice is that the router.get('*') works... I think it might be related to some async behavior on my application.

I think you can close this issue because I guess that I'm the only one that can reproduce this issue, so it's probably related to my implementation...

Thanks!

meeh0w commented 5 years ago

@Javiani @baseprime

I can confirm that this has become an issue in 0.7 -- 0.6.3 works fine. We're using this lib in an old and very limited environment (Adobe Extension) which runs Chrome 41 and hence we rely on location.hash. Older version, when reading current path in hash mode, used to only return location.hash. However, the new version returns entire location.pathname.

Because Grapnel relies on this.path() when parsing routes, and the Route object receives the location.pathname instead of location.hash, it won't recognize any of your routes and it'll end up matching the wildcard 404 (if you have it defined).

baseprime commented 5 years ago

@Javiani @meeh0w Wish we had caught this sooner. Thanks for your help!

crisperpo commented 4 years ago

I am still having this issue in version 0.7.2