-
Notifications
You must be signed in to change notification settings - Fork 12k
ng g route
should also add the route to the RouteConfig
#287
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
Comments
I'm hesitant to have the configuration of routes in a separate file. Is that a convention that we want to convey via the CLI? This solution does not scale enough to provide the ability to create routes anywhere else in the application, only at the root. There are going to be cases where internal components need to configure their own routes and that should be accomplishable via the CLI. |
I second the routes-anywhere concern voiced by @Brocco. Perhaps having child routes is fine as a future enhancement though, as top level routes cover the most common scenarios. But I agree that we need a place for cli-generated code that is completely under our control. That location needs to be part of the project, so As an aside, we already have a I do have a recommendation though: since altering/regenerating that file involves complex, error prone typescript code parsing, we should instead generate it from We will also need something similar to configure app-wide providers (like the ones Consider a
From this it is trivial to generate the needed
|
Child routes is not a concern for this issue, it's a separate issue that we need to address when doing child routes anyway. We cannot piggyback on We cannot use JSON for this as it is not IDE friendly, unfortunately. That was my first idea. The other solution is changing the Alternatively, we can have the simple solution first (external file), then implement the |
I think that directly modifying components directly is the appropriate approach here. It hides nothing from the user and they do not need to look into a different file to see the routes that are available inside a given component. |
I think perhaps I didn't explain myself properly. My strategy was to use the json file to generate the typescript file. There would always be a real code file that the IDE could use and trace. The only difference is that, when you needed to alter it, you'd re-generate it from the json data. This is much, much better than altering by parsing typescript. Unless I'm missing something here, having the external file will always imply parsing typescript, since that file is a typescript file and it needs to import the routable components. |
I made a proof of concept PR to demo what I was suggesting. See #292. Running
After running
This approach has the following benefits:
|
As a consideration to seamlessly support child routes,
This way child routes would simply have their own config. It would be trivial to implement child routes using dynamic paths as @Brocco has been implementing. |
@filipesilva for child routes would we expect something like this? |
I hadn't thought about that until you asked really! I guess the most important bit is that it needs to be something that unambiguously describes something else as the parent. It also needs to specify the relative location (to The parent must default to our defined root component. As per @Brocco's work on dynamic paths, it should support specifying a path for the component itself and also default to a certain folder if path isn't specified (both for the generated element and the parent). We should use the helper functions he made for this purpose. Using the normal
Where the following two should be equivalent:
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Tasklist:
angular-cli/router-config.ts
to the scaffold. This is part of the project. The content of this file should have a comment at the top to say to not touch this file, and export aCliRouteConfig
(open to name suggestions).README.md
to theangular-cli
directory to explain that this is generated code. We will use this for other things such as providers and third party libraries.CliRouteConfig
in the defaultsrc/app/__name__.ts
. The code should look something like [1].ng generate route
needs to add the route info to therouter-config.ts
. This includes importing the new route and adding it to theCliRouteConfig
array.ng generate route
should have a flag--no-route-generation
(open to suggestions) that avoid the addition of it to theCliRouteConfig
array.README.md
documentation for this.[1]
The text was updated successfully, but these errors were encountered: