Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Strictly typed lightweight alternatives to NgRx Router Store and ActivatedRoute.

License

NotificationsYou must be signed in to change notification settings

ngworker/router-component-store

Repository files navigation

Router Component Store

A monorepo containing Angular router state management packages that provide strictly typed, lightweight alternatives to NgRx Router Store (@ngrx/router-store) andActivatedRoute.

Packages

This repository contains two main packages:

A Component Store-based solution using observables:

  • Package:@ngworker/router-component-store
  • Technology: NgRx Component Store (@ngrx/component-store) with RxJS observables
  • Use Case: When you prefer observable-based reactivity patterns
// Observable-based APIexportclassHeroService{  #routerStore=inject(RouterStore);url$=this.#routerStore.url$;// Observable<string>searchTerm$=this.#routerStore.selectQueryParam('q');// Observable<string | undefined>}

A Signal Store-based solution using Angular Signals:

  • Package:@ngworker/router-signal-store
  • Technology: NgRx Signals (@ngrx/signals) with Angular Signals
  • Use Case: When you prefer signal-based reactivity patterns
// Signal-based APIexportclassHeroService{  #routerSignalStore=inject(RouterSignalStore);url=this.#routerSignalStore.url;// Signal<string>searchTerm=this.#routerSignalStore.selectQueryParam('q');// Signal<string | undefined>}

Common features

Both packages provide:

Strictly Typed: Full TypeScript support with strict typing
Lightweight: Minimal bundle size impact
Drop-in Replacement: For NgRx Router Store andActivatedRoute
Global & Local Stores: Application-wide and component-level usage
Immutable State: Router state is immutable and serializable
Memory Safe: Proper subscription management and cleanup

Compatibility

Both packages follow Angular's recommended release pattern for Angular libraries. One major package version for every major Angular release.

Features released in minor versions of Angular and NgRx packages are not used until the following major version package release to ensure compatibility across minor versions.

The packages require the same peer dependencies as their corresponding Angular and NgRx packages.

Quick start

Observable-based (Router Component Store)

npm install @ngworker/router-component-store
import{provideGlobalRouterStore}from'@ngworker/router-component-store';bootstrapApplication(AppComponent,{providers:[provideGlobalRouterStore()],});

Signal-based (Router Signal Store)

npm install @ngworker/router-signal-store
import{provideGlobalRouterSignalStore}from'@ngworker/router-signal-store';bootstrapApplication(AppComponent,{providers:[provideGlobalRouterSignalStore()],});

API comparison

FeatureRouter Component StoreRouter Signal Store
Current RoutecurrentRoute$: Observable<...>currentRoute: Signal<...>
Query ParametersqueryParams$: Observable<...>queryParams: Signal<...>
Route ParametersrouteParams$: Observable<...>routeParams: Signal<...>
Route DatarouteData$: Observable<...>routeData: Signal<...>
URLurl$: Observable<string>url: Signal<string>
Fragmentfragment$: Observable<...>fragment: Signal<...>
Titletitle$: Observable<...>title: Signal<...>
Router eventsselectRouterEvents(...): Observable<...>Not included to avoid an RxJS dependency

Usage patterns

Global usage (application-wide)

Both packages support global router stores for application-wide router state access:

// Component Store@Injectable({providedIn:'root'})exportclassNavigationService{  #routerStore=inject(RouterStore);currentPath$=this.#routerStore.url$;}// Signal Store@Injectable({providedIn:'root'})exportclassNavigationService{  #routerSignalStore=inject(RouterSignalStore);currentPath=this.#routerSignalStore.url;}

Local usage (component-level)

Both packages support local router stores for component-specific router state:

// Component Store@Component({providers:[provideLocalRouterStore()],})exportclassProductComponent{  #routerStore=inject(RouterStore);productId$=this.#routerStore.selectRouteParam('id');}// Signal Store@Component({providers:[provideLocalRouterSignalStore()],})exportclassProductComponent{  #routerStore=inject(RouterSignalStore);productId=this.#routerStore.selectRouteParam('id');}

Development

This repository uses:

  • Nx for monorepo, task, and CI management
  • Angular,RxJS, andNgRx
  • TypeScript
  • Jest for testing
  • Prettier andESLint for code quality

Commands

# Install dependenciesyarn install# Run testsyarntest# Run lintingyarn lint# Build packagesyarn build# Perform dead code analysisyarn knip# Run all CI checksyarn ci# Check formattingyarn format:check# Format codeyarn format

Documentation

Contributing

Contributions are welcome! Submit pull requests to the main branch.

License

MIT ©ngworkers

About

Strictly typed lightweight alternatives to NgRx Router Store and ActivatedRoute.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors6


[8]ページ先頭

©2009-2025 Movatter.jp