-
-
Notifications
You must be signed in to change notification settings - Fork 840
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
[Frontend Rewrite] Bring back current routeName #2266
Comments
Hmm, I don't know if this exact solution will work, since the attr being set was removed in ccc77dd. Although my choice of commit title was definitely poor (since this isn't obsolete, really), we now provide component classes, not component instances to mithil v2. I'm not sure that we can set this attr on the page components directly... The first thing that comes to mind is keeping track of routeNames somewhere parallel, but that doesn't seem particularly robust. Any thoughts @clarkwinkelmann @datitisev |
I feel like it'd make sense if Application knew the current route name, as it has the current and previous route data. If not, perhaps app.history ? |
Problem is, once we generate a route with app.route, there's nothing tying that to the route name. We could, of course, use a hashmap to store routes generated by |
Can we maybe use a route render method to achieve that? for (const key in routes) {
const route = routes[key];
map[basePath + route.path] = {
render() {
return m(route.component, {routeName: key});
}
};
} EDIT: but it won't be available from the global scope though... we could use the page's oninit method to then set that value on the global |
Oooo I like that! Not sure if there's any detriment to always using route resolvers though.... But then again, that was my plan for #2249 too!
Couldn't we just add that to PageState in oninit? Or somewhere? |
Yep, I've edited myself multiple times... I think it would be perfectly reasonable to set that value in the pagestate or elsewhere on the |
@clarkwinkelmann @datitisev is that something we want in the main PR, or as a separate one on top of that? |
I'm getting lost with the commits spread across multiple non-merged branches 😅 Since #2255 seems to show that it removes the old |
@clarkwinkelmann @w-4 Done in c579d66. Do we want it to be part of attrs, or it's own prop on PageState? attrs seems simpler. If we are fine with this approach, we'll need to update the relevant code in subscriptions which checks if we're on the following page. |
Just realized: I'm not sure you can have nested route resolvers. If not, this could be problematic, as it'd mean that extension devs can't use route resolvers for their own routes at all. |
@askvortsov1 Yeah I don't think that's a thing. I'm also not sure if adding that route resolver would change the behavior with how the pages themselves are rendered, re-rendered & reinitialized... |
c579d66...11b0941 should fix it. From local testing and reading, doesn't seem to change render/re-render behavior. |
The way I see it, We should create a new issue to decide how we want to let extensions add/use route matchers/resolvers and how to make sure they update the routeName when doing so. |
I'm not inherently opposed to restricting route resolvers in extensions, but I would still prefer to keep a structure similar to what I have now, which is more in compliance with what Mithril looks for in route resolvers. Perhaps, instead of accepting it, we could throw an error for now when an extension tries to use a route resolver? |
In the interest of keeping the diff as small as possible, I think c579d66 is perfectly enough for now. It fixes this issues, and doesn't introduce any behavior change from beta 13 regarding the creation of routes (apart from passing the page class instead of an instance of the class) |
Alright, I'll split the later two commits into their own PR |
The other commit that allows the use of route resolvers in extensions doesn't either though? One doesn't have to use a route resolver, but that commit allows the use of one if necessary for the use case. What's the point of updating to Mithril 2 for its benefits if we don't allow the use of some of its features? |
I'm all for enabling route resolvers for extensions, but I think this should happen outside of the Mithril v2 PR. It's big enough like it is now. If we're going to allow route resolvers, I think we need to discuss how extensions will register those while still assuring routes are resolved correctly in Flarum, and in this case particularly the So yeah... subject for another issue and another PR IMO. |
Generally speaking, I agree more with David on this one, but given the remaining issues we still need to cover (https://discuss.flarum.org/d/24758-beta-14-m2-frontend-rewrite-tests-logs), I'd prefer to take care of those first, and then return to this if we have time (or at the start of the next release cycle). I'm going to close this issue since routeName is now available again via EDIT: no it's not: individual tag pages show up as "index"...... |
Fixed in 5502056 |
Often times it's useful to get the route name of the current Page. (index, tag, ..)
I don't think it's possible anymore after #2156.
Could be easily re-implemented:
For mithril v.0.2 inside Page init():
Would make it possible to get it through
app.current.get('routeName').
The text was updated successfully, but these errors were encountered: