angular-cli/packages/angular/ssr/private_export.ts
Alan Agius d66aaa3ca4 feat(@angular/ssr): add server routing configuration API
This commit introduces a new server routing configuration API, as discussed in RFC https://github.com/angular/angular/discussions/56785. The new API provides several enhancements:

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/error',
    renderMode: RenderMode.Server,
    status: 404,
    headers: {
      'Cache-Control': 'no-cache'
    }
  }
];
```

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/product/:id',
    renderMode: RenderMode.Prerender,
    async getPrerenderPaths() {
      const dataService = inject(ProductService);
      const ids = await dataService.getIds(); // Assuming this returns ['1', '2', '3']
      return ids.map(id => ({ id })); // Generates paths like: [{ id: '1' }, { id: '2' }, { id: '3' }]
    }
  }
];
```

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/product/:id',
    renderMode: RenderMode.Prerender,
    fallback: PrerenderFallback.Server, // Can be Server, Client, or None
    async getPrerenderPaths() {
    }
  }
];
```

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/product/:id',
    renderMode: RenderMode.Server,
  },
  {
    path: '/error',
    renderMode: RenderMode.Client,
  },
  {
    path: '/**',
    renderMode: RenderMode.Prerender,
  },
];
```

These additions aim to provide greater flexibility and control over server-side rendering configurations and prerendering behaviors.
2024-09-12 19:59:05 +02:00

24 lines
890 B
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
// ɵgetRoutesFromAngularRouterConfig is only used by the Webpack based server builder.
export {
getRoutesFromAngularRouterConfig as ɵgetRoutesFromAngularRouterConfig,
extractRoutesAndCreateRouteTree as ɵextractRoutesAndCreateRouteTree,
} from './src/routes/ng-routes';
export {
getOrCreateAngularServerApp as ɵgetOrCreateAngularServerApp,
destroyAngularServerApp as ɵdestroyAngularServerApp,
} from './src/app';
export {
setAngularAppManifest as ɵsetAngularAppManifest,
setAngularAppEngineManifest as ɵsetAngularAppEngineManifest,
} from './src/manifest';
export { InlineCriticalCssProcessor as ɵInlineCriticalCssProcessor } from './src/utils/inline-critical-css';