mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-36484 improved standalone support for Core (#10998)
improved standalone support
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
# @alfresco/adf-core/shell
|
||||
|
||||
Secondary entry point of `@alfresco/adf-core`. It can be used by importing from `@alfresco/adf-core/shell`.
|
||||
Namespace: `@alfresco/adf-core/shell`.
|
||||
|
||||
This module provides the main layout for the application, allowing you to define routes and guards for your application shell.
|
||||
|
||||
# Shell
|
||||
|
||||
[ShellModule](./src/lib/shell.module.ts) is designated as a main layout for the application.
|
||||
Passed routes are going to be attached to shell main route.
|
||||
|
||||
I order to attach routes to appShell, `withRoutes(routes: Routes | AppShellRoutesConfig)` method should be used.
|
||||
```typescript
|
||||
import { provideShellRoutes } from '@alfresco/adf-core/shell';
|
||||
|
||||
Passed routes are going to be attached to [shell main route](./src/lib/shell.routes.ts)
|
||||
provideShellRoutes([/*Your Routes*/])
|
||||
```
|
||||
|
||||
If you would like to provide custom app guard, you can provide your own using [SHELL_AUTH_TOKEN](./src/lib/shell.routes.ts)
|
||||
If you would like to provide custom app guard, you can provide your own using `SHELL_AUTH_TOKEN`.
|
||||
|
||||
## Shell Service
|
||||
|
||||
In order to use `shell`, you need to provide [SHELL_APP_SERVICE](./src/lib/services/shell-app.service.ts) which provides necessary options for shell component to work.
|
||||
In order to use `shell`, you need to provide `SHELL_APP_SERVICE` which provides necessary options for shell component to work.
|
||||
|
@@ -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';
|
||||
|
@@ -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])]
|
||||
};
|
||||
}
|
||||
|
@@ -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])];
|
||||
}
|
||||
|
Reference in New Issue
Block a user