1.0.4 • Published 2 years ago

ng-cache-route-reuse v1.0.4

Weekly downloads
138
License
MIT
Repository
github
Last release
2 years ago

Angular Cache Route Reuse Strategy

A simple angular route reuse strategy with attach/detach hooks.

Getting Started

Installation:

npm install ng-cache-route-reuse --save

Import NgCacheRouteReuseModule into AppModule:

import { NgCacheRouteReuseModule } from 'ng-cache-route-reuse';

@NgModule({
  imports: [
    BrowserModule,
    AppRoutingModule,
    NgCacheRouteReuseModule,
    ...
})
export class AppModule { }

Set reuse:true in route's data to enable route reuse:

const routes: Routes = [
  ...
  {
    path: 'home',
    component: HomeComponent,
    data: {
      reuse: true
    },
  },
  ...
];

Attach/Detach Hooks

You can use hooks for performing additional subscribe/unsubscribe functionality:

import { NgCacheRouteReuseService } from 'ng-cache-route-reuse';

@Component({})
export class HomeComponent implements OnInit {
  constructor(private cacheRouteReuseService: NgCacheRouteReuseService) {}

  public ngOnInit(): void {
    this.cacheRouteReuseService
      .onAttach(HomeComponent) // or any reuse route's component
      .subscribe((component) => {
        // code...
      });

    this.cacheRouteReuseService
      .onDetach(HomeComponent) // or any reuse route's component
      .subscribe((component) => {
        // code...
      });
  }
}
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.0.0

2 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago