-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Idea: Configuring routes without the need for a dependency to call a module #486
Comments
Yeah, the idea of compiling state configurations just-in-time (i.e. as you go from config to runtime) has been brought up and would solve this problem. It's definitely something we're interested in doing, we just haven't had the time or available resources. If you're interested in hacking on this, let me know and I can point you in the right direction. |
Point away :)
|
@mboudreau Word. So, here's the entry point for state configuration: https://github.com/angular-ui/ui-router/blob/master/src/state.js#L208-L215 Either you could queue states there based on the level of depth of their parent (which would have to be normalized, since there are currently 3 ways to specify parents), or you could do some sort of dependency tracking. Then, at at top of |
(@nateabele I don't know if I'm supposed to post here or open a new issue, so sorry if I missed) I suppose this is an edge case (or blatantly unsupported), but the following is still broken in current master:
Depending on file inclusion order, it can crash as described in #488. I was able to fix it for myself by changing the order in this hard to read statement:
To this:
I didn't run the tests though. |
@rixo Yes, what you're doing is explicitly unsupported. Defining a state name as |
We're currently writing a fairly large web application with Angular 1.2-rc2 and UI-Router. We've come into contact with an issue that is a bit problematic for using ui-router. Most of our routes have their own modules because they contain quick a bit of functionality and it's easier to separate concerns, but the problem we've encountered is when you have a parent module that's dependent on a child module, where in this child module it's state parent is the original module. This would cause an error because the parent state hasn't been instantiated yet because it's still waiting for it's dependencies.
Here's an example of what I mean, this is how ui-router should function (as per the example in the docs):
The problem here is that the config of 'spaces.details' will never run unless something is dependent on it. In this app, you get to 'spaces.details' from 'spaces' which isn't a dependency per say, so our only way to actually get the config function of 'spaces.details' to run is to add that dependency to 'spaces' since it would seem like the logical place, like this:
That looks all good, but now there will be an error running it saying that 'spaces.details' route doesn't have a parent because the 'spaces.details' config function ran before it's parent ('spaces'). This circular problem is really annoying. The solution we have for now is to have all modules using ui-router to be a dependency of our main app.js file, which in turn runs all configs for every module and sets the routing properly. Furthermore, I find it annoying that the dependency model is backwards, in this case, 'spaces.details' is dependent on 'spaces' and it's data, not the other way around, which would cause confusion.
My proposed solution to this is to add a new function that can be attached after the module definition that specifies the routes and is ran the second the module is defined. Something along these lines:
And the order in which the state is called is pretty much a non issue as long as the code either adds a placeholder until the parent is defined or that if the parent is missing that it would find it before continuing the route definition.
That's about it, sorry about it being long, I was just trying to think out loud. I'd love to hear about opinions and suggestions on this. If nobody has an objection, I might try to get this working myself and do a PR when it's complete.
The text was updated successfully, but these errors were encountered: