AAE-36484 improved standalone support for Core (#10998)

improved standalone support
This commit is contained in:
Denys Vuika
2025-07-09 08:12:17 -04:00
committed by GitHub
parent 1d2cb2390b
commit 11cb2ea688
181 changed files with 678 additions and 831 deletions

View File

@@ -18,3 +18,4 @@
export * from './lib/shell.module';
export * from './lib/services/shell-app.service';
export * from './lib/components/shell/shell.component';
export * from './lib/shell.routes';

View File

@@ -16,19 +16,11 @@
*/
import { ModuleWithProviders, NgModule } from '@angular/core';
import { Routes, provideRoutes, Route } from '@angular/router';
import { SHELL_LAYOUT_ROUTE } from './shell.routes';
import { ShellLayoutComponent } from './components/shell/shell.component';
import { Routes, provideRouter } from '@angular/router';
import { AppShellRoutesConfig, SHELL_LAYOUT_ROUTE } from './shell.routes';
export interface AppShellRoutesConfig {
shellParentRoute?: Route;
shellChildren: Routes;
}
@NgModule({
imports: [ShellLayoutComponent],
exports: [ShellLayoutComponent]
})
/** @deprecated use `provideShellRoutes` instead */
@NgModule()
export class ShellModule {
static withRoutes(routes: Routes | AppShellRoutesConfig): ModuleWithProviders<ShellModule> {
if (Array.isArray(routes)) {
@@ -54,7 +46,7 @@ function getModuleForRoutes(routes: Routes): ModuleWithProviders<ShellModule> {
return {
ngModule: ShellModule,
providers: provideRoutes([shellLayoutRoute])
providers: [provideRouter([shellLayoutRoute])]
};
}
@@ -84,6 +76,6 @@ function getModuleForRouteConfig(config: AppShellRoutesConfig): ModuleWithProvid
return {
ngModule: ShellModule,
providers: provideRoutes([rootRoute])
providers: [provideRouter([rootRoute])]
};
}

View File

@@ -15,9 +15,10 @@
* limitations under the License.
*/
import { Route } from '@angular/router';
import { provideRouter, Route, Routes } from '@angular/router';
import { ShellLayoutComponent } from './components/shell/shell.component';
import { SHELL_AUTH_TOKEN } from './services/shell-app.service';
import { EnvironmentProviders } from '@angular/core';
export const SHELL_LAYOUT_ROUTE: Route = {
path: '',
@@ -25,3 +26,38 @@ export const SHELL_LAYOUT_ROUTE: Route = {
canActivate: [SHELL_AUTH_TOKEN],
children: []
};
export interface AppShellRoutesConfig {
shellParentRoute?: Route;
shellChildren: Routes;
}
/**
* Provides shell routes for the application.
*
* @param routes The routes configuration for the shell.
* @returns An array of providers for the shell routes.
*/
export function provideShellRoutes(routes: Routes | AppShellRoutesConfig): EnvironmentProviders[] {
const shellLayoutRoute = SHELL_LAYOUT_ROUTE;
if (Array.isArray(routes)) {
shellLayoutRoute.children.push(...routes);
return [provideRouter([shellLayoutRoute])];
}
const shellChildrenRoutes = routes.shellChildren || [];
if (shellChildrenRoutes.length > 0) {
shellLayoutRoute.children.push(...shellChildrenRoutes);
}
const shellParentRoute = routes.shellParentRoute;
const rootRoute = shellParentRoute || shellLayoutRoute;
if (routes.shellParentRoute) {
rootRoute.children = rootRoute.children || [];
rootRoute.children.push(shellLayoutRoute);
}
return [provideRouter([rootRoute])];
}