|
1 | | -# ngx-back-button |
2 | | -Angular back button |
| 1 | +# @ngx-translate/multi-http-loader [](https://www.npmjs.com/package/ngx-back-button) |
| 2 | + |
| 3 | +A library for handling a proper angular back button capability |
| 4 | + |
| 5 | +* [Installation](#installation) |
| 6 | +* [Usage](#usage) |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +```sh |
| 11 | +npm install ngx-back-button |
| 12 | +``` |
| 13 | + |
| 14 | +Inside your `app.module.ts` file. |
| 15 | +```typescript |
| 16 | +import { NgxBackButtonModule, NgxBackButtonService } from 'ngx-back-button' |
| 17 | + |
| 18 | + imports: [ |
| 19 | + NgxBackButtonModule.forRoot(), // Default rootUrl === '/' |
| 20 | + |
| 21 | + // Or |
| 22 | + NgxBackButtonModule.forRoot({ |
| 23 | + rootUrl: '/custom', // Or any custom root url |
| 24 | + }), |
| 25 | + ], |
| 26 | + providers: [ |
| 27 | + { |
| 28 | + provide: APP_INITIALIZER, |
| 29 | + useFactory: () => () => null, |
| 30 | + deps: [NgxBackButtonService], |
| 31 | + multi: true, |
| 32 | + }, |
| 33 | + ] |
| 34 | +``` |
| 35 | + |
| 36 | +## Usage |
| 37 | +Wherever you plan to use the back button logic |
| 38 | + |
| 39 | +```typescript |
| 40 | +import { NgxBackButtonModule } from 'ngx-back-button' |
| 41 | + |
| 42 | +imports: [ |
| 43 | + NgxBackButtonModule, |
| 44 | +] |
| 45 | +``` |
| 46 | + |
| 47 | +Then you can use it in two different way |
| 48 | + |
| 49 | +### Directive |
| 50 | +Normal use |
| 51 | +```html |
| 52 | +<button ngxBackButton> |
| 53 | + Back to login |
| 54 | +</button> |
| 55 | +``` |
| 56 | + |
| 57 | +With Fallback |
| 58 | +```html |
| 59 | +<button ngxBackButton="/login"> |
| 60 | + Back to login |
| 61 | +</button> |
| 62 | +``` |
| 63 | + |
| 64 | +### Service |
| 65 | +```typescript |
| 66 | +// foo.component.ts |
| 67 | +import { NgxBackButtonService } from 'ngx-back-button' |
| 68 | + |
| 69 | +// ... |
| 70 | + constructor(public ngxBackButtonService: NgxBackButtonService) {} |
| 71 | +``` |
| 72 | + |
| 73 | +Normal use |
| 74 | +```html |
| 75 | +<button (click)="ngxBackButtonService.back()"> |
| 76 | + Back to login |
| 77 | +</button> |
| 78 | +``` |
| 79 | + |
| 80 | +With Fallback |
| 81 | +```html |
| 82 | +<button (click)="ngxBackButtonService.back('/login')"> |
| 83 | + Back to login |
| 84 | +</button> |
| 85 | +``` |
| 86 | + |
| 87 | +## Authors and acknowledgment |
| 88 | +* maintainer [Raphaël Balet](https://github.com/rbalet) |
| 89 | +* Inspired by [Nils Mehlhirn](https://nils-mehlhorn.de/posts/angular-navigate-back-previous-page/) |
0 commit comments