Skip to content
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

Dispatching on empty string #33

Closed
shaunlebron opened this issue Jun 2, 2014 · 6 comments
Closed

Dispatching on empty string #33

shaunlebron opened this issue Jun 2, 2014 · 6 comments
Labels

Comments

@shaunlebron
Copy link

I think the following dispatch should go into the "catch all" route, but it is going to the "users" route:

(defroute "/users/:id" [id]
  (println "User" id))

(defroute "*" []
  (println "catch all"))

(secretary/dispatch! "") ; => prints "User nil"

I suppose the use-case here is to catch the default home route, but I don't see the ability here.

@noprompt
Copy link
Collaborator

noprompt commented Jun 2, 2014

Interesting. Well, that's definitely a bug.

@noprompt noprompt added the bug label Jun 2, 2014
@joelash
Copy link
Collaborator

joelash commented Jun 27, 2014

While working on fixing this, I came across an interesting question about the expected behavior here. Let's say we had the following routes.

(defroute "/" []
  (println "Home"))

(defroute "/users/:id" [id]
  (println "User" id))

(defroute "*" []
  (println "catch all"))

(secretary/dispatch! "") ; => should print "catch all" or "Home"?

Thoughts?

@shaunlebron
Copy link
Author

Oh, good catch. I think "" should be caught by "/" instead of "*". Reason being, the urls below should take the same route on a client side SPA at example.com.

http://example.com/#
http://example.com/#/

joelash added a commit to joelash/secretary that referenced this issue Jun 27, 2014
* when no index route an empty route would match first route not splat
noprompt added a commit that referenced this issue Jun 27, 2014
Fixes #33 ensure routes have / at begining
@ddellacosta
Copy link
Contributor

So, I'm finally getting around to cleaning up some old code and upgrading secretary. The upgrade (from 1.1.0 to 1.2.1) broke our site, and I traced it to this particular change: our routes are all in the form of /a#foo/a/b/c (etc.). Right now I've got a hacky workaround in place using with-redefs on the uri-with-leading-slash (which is extra ugly since it is a private fn) but it would be nice if this was at least customizable. Thoughts?

UPDATE: looks like the work @noprompt is doing here addresses this via a protocol? I agree that this could/should be handled by those using the library, so seems reasonable to use my hack for now and update when 2.0 is ready.

@noprompt
Copy link
Collaborator

noprompt commented Feb 2, 2015

@ddellacosta Hey Dave, we've been bitten by the same bug in the past but it didn't surface for us until I had been deep into the work for the next major version. Even though the branch hasn't been merged yet, we've used it in production and it works. The only reason it hasn't been merged yet is I simply haven't had enough time to update the README; that's it! Most of the information you would need to use it though is in the tests and the comments in that issue.

Since I know there are this branch really needs to get merged and the next major version out the door, I will try very hard to find time this week to do it.

@ddellacosta
Copy link
Contributor

@noprompt hey Joel, no worries of course, what I've got now should be totally workable for the time being. I'll hang on until that gets merged in, and of course don't feel any pressure to get things out the door from me! I appreciate all your work on this great lib.

(EDIT: and will check out the code in that PR in the meantime to familiarize myself with how 2.0 will work.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants