venantius / accountant

ClojureScript navigation for single-page applications, made simple.
Eclipse Public License 1.0
250 stars 39 forks source link

Support one-off exceptions to accountant #33

Closed cap10morgan closed 7 years ago

cap10morgan commented 7 years ago

Is there a way to have a link which accountant would normally preventDefault and handle instead do the default behavior? Our use case is wanting to open some content that is rendered by our SPA in a popup. accountant seems to prevent that from working.

It would be nice if we could tell accountant somehow "don't handle this one" in the <a> element itself, or if accountant detected links w/ the target attr set and didn't handle them.

venantius commented 7 years ago

It would seem to me that you could just build that filtering logic into your nav-handler function.

cap10morgan commented 7 years ago

We ended up putting it into path-exists? as a thing it checks for first and returns false if it sees this path, and that works b/c it does make accountant stay hands off for the nav part but still lets it load the content when the popup requests it. But it feels very wrong and brittle because this path does exist, we just don't want accountant to do its normal link handling on it. If we wanted to use this path anywhere else without a popup, for example, it would force a full page load.

Would you entertain a PR to make this a little cleaner?

venantius commented 7 years ago

Sure. What sort of approach did you have in mind? Some sort of id or class blacklist?

cap10morgan commented 7 years ago

Good question. I think there are a few options, and am curious which you prefer (or maybe you even know of another one I didn't think of):

  1. Check for a data-accountant="ignore" on the <a> element and leave those links to default behavior when present.
  2. Check for a particular class on the <a> element and do the same as #1 when present (I don't love this one).
  3. Just look for links that have target attrs set and leave them to default behavior.

I think my preference would be to implement both #1 and #3. Seems like it should always leave links with target attrs alone, and #1 gives people the ability to turn off accountant for individual links for whatever other reasons they might have.

venantius commented 7 years ago

My preference would be not to force any change on the template side (i.e. no data-accountant tags).

It sounds like the specific case you're worried about is one in which a link should ordinarily open a new tab or window, in which case I agree, Accountant should get out of your way and filtering on the target attr makes sense (though ideally we'd leave _self alone).

smee commented 7 years ago

There is a pull request that explicitely ignores empty/non-existing href attributes to allow accountant to know the difference between navigational links and links that are only used to trigger javascript actions.

venantius commented 7 years ago

@smee your pull request solves a different use case than the one that @cap10morgan is trying to solve, I believe.

syslo commented 7 years ago

When will this appear in the clojars?

venantius commented 7 years ago

When I merge #35, as noted in the PR.

venantius commented 7 years ago

It's up on Clojars now at 0.1.8