-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Support eagerly configuring child routers #90
Comments
+1 this would indeed be a nice enhancement. :) |
I would love this, as well. Until then, is there a workaround one could use? |
+1 for this feature, at least a workaround to avoid first route routing issue. |
+1 - fingers crossed for this! |
+1 configuring routes in the ViewModel isn't really pretty |
+1 |
For the next RC could we expected this feature ? |
+1 |
Sorry, but I don't know of any plans to work on this before 1.0. I really want it too, but I haven't had much time to spare lately. If anyone wants to work on a PR I'd be more than happy to discuss the necessary changes and answer questions. |
+1 |
+1 |
+1, any plans on this feature? |
We are working towards v1 release in the next few weeks. After that we'll look at adding some new features to the router. This is high on the list. (As this is open source, all community members are welcome to implement this and send a PR. That helps to move certain requests ahead faster.) |
I think the solution for this and #89 should address a more general scenario. Aurelia is so modular it comes natural to have an app built upon different external modules which may contribute to the route hierarchy. For example:
Then The solution I propose in #89 (comment) could work for this if it's supposed to start from the I'm willing to work on this, but since it's a bit of a work and I need to study the router internals, I'd like to know if it could be an accepted solution or not 😉 |
@heruan We'd love to have you work on it. It's a very tricky problem, especially since the child apps may not even be loaded and you've got to account for parameters and wild cards at various levels. |
I'm just studying the |
Yeah, whatever is done here, it has to be considered how it might affect bundling. To make this work, I think we would need to move the Having the Maybe this could be as simple as moving the Of course, this "eagerly look for index.ts" behavior should be explicitly enabled with a per-route option - this way it won't break existing code, and it allows some routers to be eagerly configured and others lazy. Maybe this could somehow tie in nicely with aurelia/framework#427? Does that make sense? |
I think this could be a good approach. One idea I had, just off the top of my head, was very similar. Basically, enable a separate mapper or some additional config at the app level that would provide info for generation. Child routers could maybe reference this information so they didn't need to repeat themselves. It's a difficult problem. We are open to ideas. |
I came up with this: https://github.com/heruan/aurelia-route-mapper The concept is to use a Any external application or submodule could just export its routes and the main application will configure the |
@heruan Your solution has worked really well for me! Are you planning any more work on it? |
@Kukks Yes, I'm currently working on a JavaScript object-mapper but I'm open to suggestions on how to improve the route-mapper! |
@thomas-darling I also had the similar idea, how about just making only the routes a separate file like symfony and not the whole function which could be basically models/data holders. So this way maybe it will be cheap on resources eagerly loaded. |
@heruan Thanks for the good job. I tried the demo you provided and it worked nicely. @EisenbergEffect Can we go ahead to use this? Any idea if this will be added to one of the releases soon? Thanks |
@bryanrsmith I'd love to see what you think of the solution that @heruan has come up with. It seems like we could build this into Aurelia without much work if we think it will solve the problem. Let me know what you think. |
I found this to be good solution and simple and its working ... http://www.jeremyg.net/entry/create-a-menu-with-child-routes-using-aurelia |
@heruan I've ended up using your route-mapper and its concepts and made a package for my use case where I can generate child router applications registered without loading them. |
I have a modified version of solution suggested by @activebiz. First we have to gather all the routes from all modules and after that we can use the service to generate the parent/child route combination like this: The code: https://gist.github.com/tdamir/34861b86c015e3fb5c0e25d477b11bbb |
Thanks for the mention @activebiz Just my two cents but I believe the solution proposed by @heruan is more elegant. As I mentioned in my blog post using the composition engine loads each module in the route config which could cause performance issues. I don't believe it'll retrieve any routes added using the router instead of the RouterConfiguration. |
I agree that loading modules in advance could cause performance issues and is a very hacky. I also agree that the solution @heruan proposed is more elegant and not that hacky. I might be missing something but I think that the route-mapper cannot handle parent+child navigation properly if the name of route parameters is the same (eg. parentRoute/{id}, childRoute/{id})? |
I've forked a route-mapper and handled the problem I mentioned before. If someone needs it: https://github.com/tdamir/aurelia-route-mapper |
Any update on when/if we can include any of these solutions into Aurelia itself so others can use it more easily? This seems like a huge win to just let it sit here in limbo. Any thoughts @heruan, @bryanrsmith, @EisenbergEffect? |
+1 I just struggle with that few days ago. @bryanrsmith @EisenbergEffect any plans of releasing this soon? |
@heruan are you doing anything on this still ? I've got a working solution with inspiration from your alpha, and from the nested navigation @jagonalez made. The library is a plugin that I think meets everyone's needs here. I hope to have the git repo up soon once I've finalised some aspects. Will post back here when done, am keen to get reviews. |
I recently created a little plugin ( Eager loading of childRoutes wasn't my initial plan with it, but it turned out to be really simple to add in. Essentially there's two decorators (they can both be applied to the same class):
A quick run-through of how this works:
You can access the child routes through NavModel.config.settings.childRoutes and combine the While the modules are loaded upfront in order to execute all the decorators, I don't believe this will impact initial load time too much. Apart from loading the modules, nothing really happens (no component lifecycles are invoked, no child routers are configured, etc) I'm not really sure where to take it from here, so I'm very much open to suggestions and feedback. @EisenbergEffect @bryanrsmith My idea with this is to have a sort of extra "metadata layer" on top of the router to enhance its configuration and exposure capabilities, rather than actually adding functionality to the router itself. In that light, does it make sense to keep this in a separate package (I could rename it to something else if you don't like |
Hey @davismj Can you take a look at this? Seems interesting. |
@fkleuver This is exactly what I had in mind from the start. It's going to be very at home with the .NET crowd. |
I've uploaded a sample project to showcase how to utilize this for building a navigation menu. I'm using a value converter to traverse the routeconfigs and build the url which is still a bit hacky imo. Should I add in some route generator functionality to make the href part a bit cleaner? Opinions? |
I come to the party quite late. I have implemented hierarchical nav menus since 2016 when I picked up Aurelia, and I had totally different view on this problem. To me, having delayed router config is NOT a bad thing. Dynamic behavior is good, is flexible, please don't "FIX" it. In my view, the problem here is not to show hierarchical menus of hierarchical router config. "Hierarchical menus" is pure view logic, is only presentation, you don't need to have a nested matching router model. Here is how my top level router config would look like.
Instead of |
@huochunpeng
I completely agree with you there. And the example you gave does work fine in most smaller projects.
Maybe not for a shallow admin panel or line-of-business application where you know the structure upfront. This is a key point for me: It's about automation and compositionTo create a large-scale dynamic data-driven website completely in Aurelia with limited time and resources, manually keeping multiple layers in sync (server-and-client, view-and-viewmodel, navigation-and-routerconfig, etc) is the biggest time sink by a mile. How well this is managed is literally what makes or breaks a project. I use code generation for things like services, models and view-models based on C# (long live Roslyn), and have lots of small composable template parts to let Aurelia stitch it all together based on the data at run-time. Aurelia's strength, for me, lies in its amazing ability to compose. It's like having a DSL for the UI. Except when it comes to navigation?It seems like it always needs to be done from scratch (more or less) so this is where I currently spend 80% or so of my time. You can't do this to visitors of a webshop, you want to give those extensive exploration options. I for one hate it when I need to click through multiple times just to see the next level of categories. And you can't do it to yourself to put all of that in the top-level route config settings when you've got a million products with arbitrarily deep category structures. You can't really generate that either (generation works better with "one per file" principle). And having a separate model for the menu means you don't have things like .isActive and properly generated routes. Conclusion:
So I'm committed to it for one. @davismj maybe this is really a |
@fkleuver I understand your argument, you want the framework to help to organize the code. My argument is, I might not need much from the framework in order to meet this. Since your complex structured routes are static anyway, why not push them up to top level routes definition. You can have some code to automate the routes creation without fighting the framework. This is just my view, I understand everyone have different opinion and approach. And aurelia is permissive enough to tolerant me :-) I was very hard to breath in react. BTW, we have something in common. I hate AZURE portal ui too with a passion (if that's what you mean). FYI, my front-end apps are not small projects. The following stats is for (biggest) one of my apps. I have separate front-end domain logic lib and shared front-end ui lib (they have about 8k lines in addition). Similar to what you described, my apps are heavily driven by meta-data to compose the view. Just put here for reference.
|
@fkleuver I think this is a 2.x level change. Appreciate the feedback, extremely useful. |
@huochunpeng
Correct, and I acknowledge that in the end this boils down to coder preference and experience. I put a lot of work into my codegen templates to make the output as robust and feature-rich as possible. Popular tools such as the Visual Studio TypeWriter extension and T4 templates generate one output file per input file. I've had to resort to wonky build scripts to concatenate some of these outputs and you get all these "don't touch it once it works" artifacts that (for me) make a project more volatile over time. However even without code generation, I quite fancy the idea of creating the pages that I want, configuring everything related to those pages on those pages, then in my app just reference the moduleIds and everything just wires up like magic. Navigation included. Aurelia already works like that for the most part (it does SO. MUCH. STUFF. under the covers) so why not have that magic for routing as well, is my thought here. @Kukks That's a pretty neat concept, thanks for the link! |
I've made several updates to the plugin and in it's current form is actually serving me pretty well in a moderately sized app. Using it for the decorator convention-based configuration though, so I haven't really tested the navigation-templating side of things that much. I'm guessing next steps are to make the regular |
Lazily configuring child routers has a couple downsides:
If we let child routers be eagerly configured we could implement features that require knowledge of the whole apps routing structure. Ideas:
The text was updated successfully, but these errors were encountered: