Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexmngn/ember-route-history
https://github.com/alexmngn/ember-route-history
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/alexmngn/ember-route-history
- Owner: alexmngn
- License: mit
- Created: 2015-10-27T22:15:40.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T10:53:54.000Z (about 2 years ago)
- Last Synced: 2024-11-20T05:29:17.375Z (about 2 months ago)
- Language: JavaScript
- Size: 945 KB
- Stars: 16
- Watchers: 2
- Forks: 13
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Ember-route-history [![Build Status](https://travis-ci.org/alexmngn/ember-route-history.png?branch=master)](https://travis-ci.org/alexmngn/ember-route-history)
This is an Ember-CLI addon. It provides a service which keeps an history of the visited routes. You will be able to know what is the current route, and what was the previously visited routes.
## Installation
Using ember-cli:
```
ember install ember-route-history
```## Usage
By default, **the service is injected into all routes of your application**. You can also inject it in any controllers, components or other services.
**You need to extend the `RouteHistoryMixin` in the routes you would like to keep an history of.** If you don't use this mixin in a certain route, it won't be tracked.
If you don't want to add this mixin for all your routes, you can simply create a base route that will extend this mixin, then you can extend your base route on all the routes of your application.
```js
import Ember from 'ember';
import RouteHistoryMixin from 'ember-route-history/mixins/routes/route-history';export default Ember.Route.extend(RouteHistoryMixin, {
/* Your code here */
});
```To use it, in a component for example:
```js
export default Ember.Component.extend({
routeHistory: Ember.inject.service(),onInsert: Ember.on('didInsertElement', function () {
const currentRouteName = this.get('routeHistory.current'); // Returns the current route name.
const previousRouteName = this.get('routeHistory.previous'); // Returns the name of the previously visited route.
const fullRouteHistory = this.get('routeHistory.history'); // Returns an array of route names.
}
});
```By default, only 10 items are saved in the history. You can increase the size of the stack by setting `maxHistoryLength`.
```js
this.set('routeHistory.maxHistoryLength', 50);
```