Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rbalet/ngx-back-button

Angular back button
https://github.com/rbalet/ngx-back-button

Last synced: about 2 months ago
JSON representation

Angular back button

Awesome Lists containing this project

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 } from 'ngx-back-button'

imports: [
NgxBackButtonModule.forRoot({}), // Default rootUrl === '/'

// Or
NgxBackButtonModule.forRoot({
rootUrl: '/custom', // Or any custom root url
fallbackPrefix: '/tabs' // For libraries users
}),
],
```

### 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

Back to login

```

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

Back to login

```

## 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

Back button

```

With Fallback
```html

Back to login

```

### Service
```typescript
// foo.component.ts
import { NgxBackButtonService } from 'ngx-back-button'

// ...
constructor(public ngxBackButtonService: NgxBackButtonService) {}
```

Normal use
```html

Back button

```

With Fallback
```html

Back to login

```

## 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)