-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Raphaël Balet | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,125 @@ | ||
Fix missing npm README | ||
# @ngx-back-button | ||
A library for handling a proper angular back button capability | ||
|
||
![NPM](https://img.shields.io/npm/l/ngx-back-button) | ||
[![npm version](https://img.shields.io/npm/v/ngx-back-button.svg)](https://www.npmjs.com/package/ngx-back-button) | ||
![npm bundle size](https://img.shields.io/bundlephobia/min/ngx-back-button) | ||
![npm](https://img.shields.io/npm/dm/ngx-back-button) | ||
|
||
1. Handle Browser history | ||
2. Handle `Fallback` when clicking on the back button when not routed yet | ||
3. Handle custom `Fallback` | ||
|
||
## Demo | ||
- https://stackblitz.com/~/github.com/rbalet/ngx-back-button | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install ngx-back-button | ||
``` | ||
|
||
Inside your `app.module.ts` file. | ||
```typescript | ||
import { NgxBackButtonModule, NgxBackButtonService } from 'ngx-back-button' | ||
|
||
imports: [ | ||
NgxBackButtonModule.forRoot({}), // Default rootUrl === '/' | ||
|
||
// Or | ||
NgxBackButtonModule.forRoot({ | ||
rootUrl: '/custom', // Or any custom root url | ||
fallbackPrefix: '/tabs' // For libraries users | ||
}), | ||
], | ||
providers: [ | ||
{ | ||
provide: APP_INITIALIZER, | ||
useFactory: () => () => null, | ||
deps: [NgxBackButtonService], | ||
multi: true, | ||
}, | ||
] | ||
``` | ||
|
||
### rootUrl | ||
The default fallback in case your landing on the page and have nothing to go back to | ||
|
||
### fallbackPrefix | ||
Added to the fallback argument. | ||
|
||
Use: If you're building a library, wish to put some back button with fallback. | ||
|
||
Let say, you build a component that have the following | ||
```html | ||
<button ngxBackButton="/login"> | ||
Back to login | ||
</button> | ||
``` | ||
|
||
But inside your app, you always have the `/tabs` first. | ||
|
||
Adding `fallbackPrefix: '/tabs'` will be the same as if you were doing the following | ||
|
||
```html | ||
<button ngxBackButton="/tabs/login"> | ||
Back to login | ||
</button> | ||
``` | ||
|
||
## Usage | ||
Wherever you plan to use the back button logic | ||
|
||
```typescript | ||
import { NgxBackButtonModule } from 'ngx-back-button' | ||
|
||
imports: [ | ||
NgxBackButtonModule, | ||
] | ||
``` | ||
|
||
Then you can use it in two different way | ||
|
||
### Directive | ||
Normal use | ||
```html | ||
<button ngxBackButton> | ||
Back button | ||
</button> | ||
``` | ||
|
||
With Fallback | ||
```html | ||
<button ngxBackButton="/login"> | ||
Back to login | ||
</button> | ||
``` | ||
|
||
### Service | ||
```typescript | ||
// foo.component.ts | ||
import { NgxBackButtonService } from 'ngx-back-button' | ||
|
||
// ... | ||
constructor(public ngxBackButtonService: NgxBackButtonService) {} | ||
``` | ||
|
||
Normal use | ||
```html | ||
<button (click)="ngxBackButtonService.back()"> | ||
Back button | ||
</button> | ||
``` | ||
|
||
With Fallback | ||
```html | ||
<button (click)="ngxBackButtonService.back('/login')"> | ||
Back to login | ||
</button> | ||
``` | ||
|
||
## Authors and acknowledgment | ||
* maintainer [Raphaël Balet](https://github.com/rbalet) | ||
* Inspired by [Nils Mehlhirn](https://nils-mehlhorn.de/posts/angular-navigate-back-previous-page/) | ||
|
||
[![BuyMeACoffee](https://www.buymeacoffee.com/assets/img/custom_images/purple_img.png)](https://www.buymeacoffee.com/widness) |