nx icon indicating copy to clipboard operation
nx copied to clipboard

feat(angular): create routes file pattern

Open Coly010 opened this issue 3 years ago • 2 comments

Description

This PR introduces a pattern of separate *.routes.ts files for generated routes. The idea behind this is fairly straightforward. Routes will always live in a separate file where a variable is exported containing the array of Routes.

The motivation for this is two-fold.

  1. It is much easier for developers to find and reason about routing within their apps when the routes are always contained in a specific file.
  2. With the introduction of Standalone Components in Angular, routing to children no longer needs a RouterModule.forChild, it simply uses a variable containing a route configuration. By introducing this pattern, we align how routing is set up for both NgModule-based and Standalone Component-based Angular workspaces. This also increases the interoperability between them.

By aligning them to follow the same pattern, we also simplify the code required to add a Route to an existing Route configuration.

Below is the file structure that will be created

| - apps
   | - appName
     | - src
       | - app
         | - app.routes.ts
| - libs
  | - libName
    | - src
      | - lib
        | - lib.routes.ts

This works for Standalone Apps and Libraries and NgModule Apps and Libraries and interops between them. It also works for Module Federated Apps, both Standalone and NgModule-based.

Coly010 avatar Sep 08 '22 14:09 Coly010

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
nx-dev ✅ Ready (Inspect) Visit Preview Sep 14, 2022 at 4:11PM (UTC)

vercel[bot] avatar Sep 08 '22 14:09 vercel[bot]

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

github-actions[bot] avatar Mar 17 '23 17:03 github-actions[bot]