refractor: core module (#289)
* Shift services into their own folders. * Add comments. Fixes #288
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/** Angular Imports */
|
||||
import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router';
|
||||
|
||||
/**
|
||||
* A route strategy allowing for explicit route reuse.
|
||||
* Used as a workaround for https://github.com/angular/angular/issues/18374
|
||||
* To reuse a given route, add `data: { reuse: true }` to the route definition.
|
||||
*/
|
||||
export class RouteReusableStrategy extends RouteReuseStrategy {
|
||||
|
||||
public shouldDetach(route: ActivatedRouteSnapshot): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle | null): void { }
|
||||
|
||||
public shouldAttach(route: ActivatedRouteSnapshot): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
public shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
|
||||
return (future.routeConfig === curr.routeConfig) || future.data.reuse;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
// import { AuthenticationService } from '../authentication/authentication.service';
|
||||
// import { MockAuthenticationService } from '../authentication/authentication.service.mock';
|
||||
// import { AuthenticationGuard } from '../authentication/authentication.guard';
|
||||
// import { ShellComponent } from './shell/shell.component';
|
||||
// import { Route } from './route.service';
|
||||
|
||||
// describe('Route', () => {
|
||||
// let route: Route;
|
||||
|
||||
// beforeEach(() => {
|
||||
// TestBed.configureTestingModule({
|
||||
// providers: [
|
||||
// AuthenticationGuard,
|
||||
// { provide: AuthenticationService, useClass: MockAuthenticationService },
|
||||
// Route
|
||||
// ]
|
||||
// });
|
||||
// });
|
||||
|
||||
// beforeEach(inject([Route], (_route: Route) => {
|
||||
// route = _route;
|
||||
// }));
|
||||
|
||||
// describe('withShell', () => {
|
||||
// it('should create routes as children of shell', () => {
|
||||
// // Prepare
|
||||
// const testRoutes = [{ path: 'test' }];
|
||||
|
||||
// // Act
|
||||
// const result = Route.withShell(testRoutes);
|
||||
|
||||
// // Assert
|
||||
// expect(result.path).toBe('');
|
||||
// expect(result.children).toBe(testRoutes);
|
||||
// expect(result.component).toBe(ShellComponent);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
@@ -0,0 +1,31 @@
|
||||
/** Angular Imports */
|
||||
import { Route as ngRoute, Routes } from '@angular/router';
|
||||
|
||||
/** Custom Components */
|
||||
import { ShellComponent } from '../shell/shell.component';
|
||||
|
||||
/** Custom Guards */
|
||||
import { AuthenticationGuard } from '../authentication/authentication.guard';
|
||||
|
||||
/**
|
||||
* Provides helper methods to create routes.
|
||||
*/
|
||||
export class Route {
|
||||
|
||||
/**
|
||||
* Creates routes using the shell component and authentication.
|
||||
* @param routes The routes to add.
|
||||
* @return {Route} The new route using shell as the base.
|
||||
*/
|
||||
static withShell(routes: Routes): ngRoute {
|
||||
return {
|
||||
path: '',
|
||||
component: ShellComponent,
|
||||
children: routes,
|
||||
canActivate: [AuthenticationGuard],
|
||||
// Reuse ShellComponent instance when navigating between child views
|
||||
data: { reuse: true }
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user