-
Notifications
You must be signed in to change notification settings - Fork 421
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
can-href link helper #1103
Comments
Another option ... Custom Attribute that hooks up other attributes
Pros - still a link, fits in with how components get hooked up. |
<a can-href route-page="recipe" route-id='{recipe.id}'>{{recipe.name}}</a> |
IMO helpers like I see custom attribute or custom elements as a better way, as you are free to modify the html tag as you see fit. Could you pass a json like object to the custom attr version? e.g.
However I'm confused about the possible syntax. Some common patterns I use: /#recipes The first two are clear, how would you express the others? |
We are going the
This depends on what pretty routes you setup. Put probably like:
|
I think is worth looking at how the API is resolved in React-Routes https://github.com/rackt/react-router/blob/master/docs/api/components/Link.md Something like:
I find this very easy to understand. But they rely heavily on named routes for this which Can doesn't have atm. Anyway, something to consider. |
What's about:
? Does React have 2 way routing? CanJS treats all data the same. There is no "params" vs "query" data. The determinism of CanJS's routing, although confusing at first, is very powerful. I don't think named routes would be a benefit. |
No, I don't think that React-routes does two way route binding. This is a convoluted example but worth using, how would you link to:
In React-Routes you would do:
|
@sporto it's all about how you setup your pretty routes. But any other "how to do canjs routing" questions, please ask on the forums. There's a lot of ways to structure your pretty routes depending on the situation. If you're site was pretty uniform in the url structure, you could do: can.route("user/:userId/:part/:action",{type: "user"}); and <a can-href="{type: 'user', userId: user.id, part: 'comments', action: 'search', foo: 'bar'}">Search</a> If we made it possible to set "merge" and you were currently on the user/1 page, you would only have to write something like: <a can-href="{part: 'comments', action: 'search', foo: 'bar'}" can-href-merge>Search</a> I suppose some naming might help make things nicer. Being able to mixin: can.route("user/:userId/comments/search",
{type: "user",part: "comments", action: "search"},
"user_comments_search") <a can-href="{route: 'user_comments_search'}" can-href-merge>Search</a> |
I currently use these helpers: https://github.com/stevenvachon/can-boilerplate/blob/master/root/client/private/components/app/helpers/urls.js like <a href="{{app-route-section 'something'}}">something</a> |
maybe this should be can-route as the attribute name. |
I think |
For consistency, I think we are going to go with this:
This will be easiest to implement and work similar to can-EVENT and passing options to helpers.. |
can-hrefSets an element's href attribute so that it's url will set the specified attribute values on [can.route]. @siganture @param {String} attrName UseWith no pretty routing rules, the following:
produces:
If pretty route is defined like:
The previous use of
You can use values from stache's scope like:
If
If
|
Wouldn't |
@stevenvachon it wouldn't be more mustache/stache like. Plus we already have a parser for |
Ah, yes: http://handlebarsjs.com/expressions.html#helpers |
This has been added in 2.3 (but is already deprecated in favour of the |
VOTE HERE
We should add a
link
stache/mustache helper or component or custom attribute.Helper
Pros - I like the syntax
Cons - Can't easily pass the "style" argument to can.route.link.
Custom Attribute
Pros - can customize the style, happens directly on a link.
Cons - UGLY
Custom element
Pros - pretty, fits in with how components get hooked up
Cons - What about attributes that should be ignored? Do we need a syntax of specifying that? We'd have to add "style". Maybe
data-X
prevents cross binding on that property?Qs - would we put an
<a>
inside or would we implement click / keypress ourselves?A - we would have to put the
<a>
inside if we want right click and open in new window ... indexing ... etc.The text was updated successfully, but these errors were encountered: