• This repository has been archived on 28/Jul/2018
  • Stars
    star
    182
  • Rank 211,154 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bindings to connect the Angular Router to @ngrx/store

This repository is for version 1.x of of @ngrx/router-store.

Click here for the latest version (4.x)


@ngrx/router-store

Bindings to connect angular/router to ngrx/store

Join the chat at https://gitter.im/ngrx/store

Installation

npm install @ngrx/[email protected] --save

Setup

  1. Use the routerReducer when providing the StoreModule.provideStore and add the RouterStoreModule.connectRouter to the @NgModule.imports:
import { StoreModule } from '@ngrx/store';
import { routerReducer, RouterStoreModule } from '@ngrx/router-store';

@NgModule({
  imports: [
    BrowserModule,
    StoreModule.provideStore({ router: routerReducer }),
    RouterStoreModule.connectRouter()
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule {
}
  1. Add RouterState to main application state:
import { RouterState } from '@ngrx/router-store';

export interface AppState {
  router: RouterState;
};
  1. (Optional) Set the initial value for the router state:
StoreModule.provideStore({ router: routerReducer }, {
  router: {
    path: window.location.pathname + window.location.search
  }
})

Dispatching Actions

import { go, replace, search, show, back, forward } from '@ngrx/router-store';

Navigation with a new state into history

store.dispatch(go(['/path', { routeParam: 1 }], { query: 'string' }));

Navigation with replacing the current state in history

store.dispatch(replace(['/path'], { query: 'string' }));

Navigation without pushing a new state into history

store.dispatch(show(['/path'], { query: 'string' }));

Navigation with only changing query parameters

store.dispatch(search({ query: 'string' }));

Navigating back

store.dispatch(back());

Navigating forward

store.dispatch(forward());

Navigation Extras

The Angular Router Navigation Extras are supported with each router action.

import { NavigationExtras } from '@angular/router';

let extras: NavigationExtras = {
  relativeTo: ActivatedRoute,
  fragment: string,
  preserveQueryParams: boolean,
  preserveFragment: boolean,
  skipLocationChange: boolean,
  replaceUrl: boolean
};

store.dispatch(go(['path', { routeParam: 1 }], { query: 'string' }, extras));

More Repositories

1

platform

Reactive State for Angular
TypeScript
7,986
star
2

store

RxJS powered state management for Angular applications, inspired by Redux
TypeScript
3,908
star
3

example-app

Example app showcasing the ngrx platform
TypeScript
1,362
star
4

effects

Side effect model for @ngrx/store
TypeScript
532
star
5

store-devtools

Developer Tools for @ngrx/store
TypeScript
326
star
6

router

Reactive Router for Angular
TypeScript
269
star
7

db

RxJS powered IndexedDB for Angular apps
TypeScript
186
star
8

ngrx.github.io

Reactive Extensions for Angular
HTML
114
star
9

notify

Web Notifications Powered by RxJS for Angular
TypeScript
101
star
10

core

Core functionality for the ngrx platform
TypeScript
72
star
11

store-log-monitor

Log Monitor for @ngrx/store-devtools and Angular
TypeScript
63
star
12

signal-store-workshop

Source Code for NgRx SignalStore Workshop
TypeScript
29
star
13

store-builds

@ngrx/store build artifacts
JavaScript
16
star
14

store-devtools-builds

@ngrx/store-devtools build artifacts
JavaScript
10
star
15

entity-builds

@ngrx/entity build artifacts
JavaScript
8
star
16

component-store-builds

@ngrx/component-store build artifacts
JavaScript
6
star
17

angular

TypeScript
5
star
18

signals-builds

JavaScript
4
star
19

schematics-builds

@ngrx/schematics build artifacts
4
star
20

ngrx-io-builds

ngrx.io builds
HTML
4
star
21

router-store-builds

@ngrx/router-store build artifacts
JavaScript
2
star
22

ngrx-io-previews

ngrx.io preview builds
HTML
1
star
23

ngrx-modules-workshop

NgRx Global store workshop - module-based application
TypeScript
1
star
24

signal-store-starter

Stackblitz Project for the SignalStore
TypeScript
1
star
25

ngrx-standalone-workshop

TypeScript
1
star
26

data-builds

@ngrx/data build artifacts
JavaScript
1
star
27

effects-builds

@ngrx/effects build artifacts
JavaScript
1
star