meteor-activeroute/legacy

Use parameters in routes

mazing opened this issue · 17 comments

Is it possible to use parameters in the routes just like iron-router provides {{pathFor 'profilePage' _id=userId}}?

zimme commented

For this {{isActiveRoute 'home'}} syntax I don't think I support that right now, one thing you could do is this {{isActiveRoute name='home' _id=userId}}.

I'll look into supporting syntax you talked about and see what I can do.

zimme commented

I'll keep this open until I've had a look at supporting the syntax you talked about, because I've actually been thinking about that before.

zimme commented

So thinking about this, did you mean that support for parameters that would match against the route's parameters and only return the active class if they also matches? or did you mean for the helpers settings parameters like class and regex? or maybe both?

How was it implemented?
In my case I want to check if the route parameters match against the specified parameters. Is this possible right now?

zimme commented

Oooh, my bad. I only solved half the issue. I now support adding parameters to the syntax you talked about, but I don't check if any of the parameters match the route's parameters and use that to do specific matching.

I've been thinking about implementing this, but as you can use {{isActivePath pathToMatch}} where pathToMatch is a template helper which returns the specific route's uri with the _id to match against.
I didn't implement parameter specific matching with isActiveRoute, but enough people have been asking about it so I'll re-open this issue and track the feature here.

Here's another way of doing the same thing.

<ul>
  <li class="{{isActivePath path}}">
    {{#linkTo route='profilePage'}}Profile Page{{/linkTo}}
  </li>
<ul>
Template.<name>.helpers({
  path: function() {
    return 'user/' + this._id;
  }
});

This example assumes the data context of the template is the user object of the user, who's profile you wanna link to.

zimme commented

I never ran into this problem because I usually have 2 routes, profile and showUser, which uses the same templates to show a users profile. The difference here is that when I wanna link to the "me" page I just match against profile with isActiveRoute instead of needing to match against a specific user.

But I can see the need for this convenience functionality.

I see... In my case I have a "iPad-like" Master-Detail view with a list on the left side. On the right side is the content of the active item in the list. Each item have the same route but a different _id parameter.
With iron router's pathFor it's very easy to create a link to the item's route

<a href="{{pathFor 'item.detail'}}>{{name}}</a>

pathFor automatically match the parameters of the route with the properties of this. It would be very cool to have the same behaviour with isActiveRoute.

zimme commented

So, I actually implemented the data context inheritance, but as a lot of people had objects in the data context which had class and route properties. So I realized that this wasn't a good fit for this package.

But when I'm implementing the specific matching part with parameters, I'll look into inheriting from the data attribute like so. {{isActiveRoute 'item.detail' data=this}}, where this is the item object which will be used for specific matching.

However, after this is implemented and you feel that you really want the data context inheritance we can open a new issue to track that. I could most likely add that again but as an opt-in feature. i.e. ActiveRoute.config({ inheritData: true });

Edit:
I could probably have data context enabled by default, but filter out active-route specific attribute options.

zimme commented

This should be possible now with version 2.3.3-rc.1

{{isActiveRoute 'showUser' _id='1241251'}}
{{isActiveRoute 'showUser' data=currentUser}}

class, className, data, regex, name or path will be excluded because these are ActiveRoute
options, and routes such as this: /schedule/:class won't work with specific matching and you will need to
use {{isActivePath dynamicPath}} approach.

Also take note that data context inheritance must be explicitly assigned as you would have to do with {{Template.dynamic ...}}

Zimme I've updated to 2.3.3-rc.1 and tried to match the route /profile/:position and url /profile/test
{{isActiveRoute 'profile' position="test"}} returns empty
{{isActiveRoute 'profile'}} returns "active"

Is there something I need to do more?

zimme commented

Hmm, should work with the latest rc, can't really reprod now as Im on vacation. Ill try to get to it as soon as possible

There is actually an optional language route group over this. so real url is /:lang/profile/:position maybe this breaks something?

zimme commented

Most likely

On Wed, Mar 16, 2016, 9:17 PM ipa1981 notifications@github.com wrote:

There is actually an optional language route group over this. so real url
is /:lang/profile/:position maybe this breaks something?


You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
#31 (comment)

hey, what if i use iron router and my url has query like achievements?type=differentType,

how do i make it "active"

zimme commented

hey, what if i use iron router and my url has query like achievements?type=differentType,

how do i make it "active"

Use the isActivePath helper.

zimme commented

There's a problem with the latest stable version of this package and Meteor 1.4+ versions where template helpers for blaze don't seem to be working properly.

See issue #52.

zimme commented

You could try the new activeroute:core, activeroute:iron-router/activeroute:flow-router and activeroute:blaze packages that I've created which are more modular and should work properly with Meteor 1.4+.