Support for grouped/prefixed routes
Opened this issue · 10 comments
Hi there, just trying to see if there is any current support for prefixed routes? This doesn't seem to be working at present for me.
Thanks.
If it's the active route helpers then you can use regex to match the prefix part of the url using isActivePath
/isNotActivePath
helpers. {{isActivePath regex="^/prefix/"}}
Thanks @zimme actually this is for the pathFor
helper
Hi @andregoldstein
sorry to come back to you so late on this issue.
I don't fully understand what u mean. Do you mean running the app in a subfolder like https://github.com/kadirahq/flow-router#prefixed-paths
or do you mean using FlowRouter.group ?
Both seem to work fine for me. pathFor
for a route defined inside a group can be just addressed with the name parameter of the route.
Let me know and I will try to look a bit deeper. Perhaps some code example would be helpful
Maybe the OT refers to the ability to use pathFor addressing a route group and only the ("local") route name?
To explain with an example, if we have:
var adminRoutes = FlowRouter.group({
prefix: "/admin",
name: "admin"
});
adminRoutes.route("/profiles", {
name: "profiles"
});
then being able to write something like:
<a href="{{pathFor 'profiles' 'admin'}}">
that results in a link to /admin/profiles
Currently, as you already stated, we're forced to use absolute route names even for group routes, that ruins in part the usefulness of group routes (IMO).
+1 currently using route names if I am actively in a grouped route then try and leave that group using links from pathFor I can't.
@sean-stanley I don't fully understand the use-case here. Can you provide me with some more examples?
@think01 your example is valid, but personally I would just prefix the group name into the sub routes, like
var adminRoutes = FlowRouter.group({
prefix: "/admin",
name: "admin"
});
adminRoutes.route("/profiles", {
name: "adminProfiles"
});
Then you would just pass in one parameter as always to the pathFor helper
<a href="{{pathFor 'adminProfiles'}}">
In my opinion route names should be actually unique.
On the other hand, modifying the helper to allow for an optional group parameter could be a bit tricky, since FlowRouter.path(pathDef, params, queryParams) just takes a path definition and returns a url.
If you can provide a more concrete example I am happy to look into it again.
Actually I found my issue was something else. pathFor works as expected navigating between groups. I agree route names should be unique. I like the convention of naming them admin.profiles
though camel case works too for sub routes naming.
@banglashi thx for the reply. I understand modifying the helper can be a bit tricky (and not wise, overall).
Personally I'ld find useful (because it leds to more clean and concise code) to have the group name implicitly added to a sub-route name, like this:
var adminRoutes = FlowRouter.group({
prefix: "/admin",
name: "admin"
});
adminRoutes.route("/profiles", {
name: "profiles"
});
This should create the group route named "admin.profiles" with path "/admin/profiles":
<a href="{{pathFor 'admin.profiles'}}">
It fixes the logic discrepancy between how paths and names are specified in group.route() calls (the path is relative to the group path while the name is absolute).
Just my 2c.
+1 for @think01;
Now could I use it?
@thearabbit sorry I'm not sure but I fear not, since this issue is still open.