angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

AngularNodeAppEngine : dynamic route paths added with Router.resetConfig during AppInitializer can't be reached on SSR

Open jimjim2a opened this issue 11 months ago • 4 comments

Command

build

Description

Hello everyone,

I'm currently trying to migrate an Angular 18 app with SSR enabled using CommonEngine. After switching to V19 I wanted to move to AngularNodeAppEngine to be able to have hybrid rendering but I'm facing an issue with dynamic route paths.

The app we are working on, by default, has no pre-defined route paths. They all come from an API. The end user can edit all the slugs of its app on a dedicated interface.

So, during APP_INITIALIZER we fetch the routes from the API and Router.resetConfig. This is working using CommonEngine.

But it doesn't when using AngularNodeAppEngine because of the route extraction phase during build time to feed the Manifest in this scenario.

When the app is built, let's say the end user has only activated one route routeA. The server manifest has only a route.

But after some time, the end user chose to add another route to the app (routeB). During APP_INITIALIZER the route is correctly added to the router config, but since it's not part of the manifest, routeB leads to a 404 on SSR.

Minimal Reproduction

I added a repo to highlight the issue : https://github.com/jimjim2a/ssr-dynamic-routing.

Here are the steps to reproduce the issue :

  1. Build the app -> at this time route extraction knows only "article" route
  2. open the "/article" page -> During app initializer we now add a second route ("video")
  3. Click on the "Go to Video page !" button -> This works since the second route is added on CSR
  4. Refresh the "/video" page -> This path can not be found and leads to a 404

We are in case there both SSR and CSR Router has correct configuration, but since the manifest extracted during build time is not complete, the SSR of the newly added route leads to 404.

Your Environment

Angular CLI: 19.0.6
Node: 20.14.0
Package Manager: npm 10.7.0
OS: darwin x64

Angular: 19.0.5
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.6
@angular-devkit/build-angular   19.0.6
@angular-devkit/core            19.0.6
@angular-devkit/schematics      19.0.6
@angular/cli                    19.0.6
@angular/ssr                    19.0.6
@schematics/angular             19.0.6
rxjs                            7.8.1
typescript                      5.6.3
zone.js                         0.15.0

Thanks everyone for all the great Job you're doing !

jimjim2a avatar Dec 31 '24 09:12 jimjim2a

Since routes are required at build time, this is not something that can be handled dynamically. However, we could potentially provide a helper method to repopulate the routing table.

alan-agius4 avatar Jan 06 '25 09:01 alan-agius4

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

angular-robot[bot] avatar Jan 06 '25 13:01 angular-robot[bot]

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

angular-robot[bot] avatar Feb 15 '25 13:02 angular-robot[bot]

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

angular-robot[bot] avatar Mar 06 '25 13:03 angular-robot[bot]

@alan-agius4 Can we reopen this ticket to revote ?

sajay-g avatar Jun 10 '25 14:06 sajay-g

@sajay-g, you can add a thumbs up. The issue is still open.

alan-agius4 avatar Jun 10 '25 14:06 alan-agius4

Since routes are required at build time, this is not something that can be handled dynamically. However, we could potentially provide a helper method to repopulate the routing table.

@alan-agius4 Is this something you're intending to provide? Adding routes during runtime is very useful.

If not maybe you can give some hint how you would implement dynamic routes as a framework consumer. Even if this means it's a workaround. Dynamically setting client rendered routes within provideServerRouting seems pretty tricky right now.

yackinn avatar Aug 04 '25 18:08 yackinn

Closing this issue for now as it's not currently planned. We will reconsider it if we see increased community demand

alan-agius4 avatar Oct 21 '25 12:10 alan-agius4

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.