1.3.2 • Published 6 years ago
mfrouter v1.3.2
mfrouter
Exports history-like object for every platform.
History API
length: number
Property that returns the count of entries. Will be 1
when page is loaded.
back(): void
Gets one page back
forward(): void
Gets one page forward if possible
go(steps: number): void
Goes steps
back or forward
pushState(state: any, url: string, title: string): void
Create a new entry in history
replaceState(state: any, url: string, title: string): void
Replaces the last entry in the history
subscribe(listener: Function): Function
Custom is part of mfrouter
only. Binds a listener to history changes (from inside code as well as from outside). Returns a function that removes that listener
History Location mixin API
http://test.com/page?query=2#some-hash
| | | | |
| | | | +--hash
| | | +--search
| | +--pathname
| +--host
+--protocol
href(): string
Returns current page full path (http://test.com/page?query=2#some-hash
)
protocol(): string
Return protocol (http:
)
host(): string
Returns host (test.com
)
pathname(): string
Returns pathname (/page
)
search(): string
Returns query string (?query=2
)
hash(): string
Returns hash part of url (#some-hash
)
Example
Cordova
const fakeHistoryFactory = require('mfrouter/fake');
const history = fakeHistoryFactory();
// Will go back with history when backbutton is pressed
// If no history entries will leave
document.addEventListener('deviceready', function () {
document.addEventListener('backbutton', function (e) {
e.preventDefault();
e.stopPropagation();
if (history.length > 1)
history.back();
else
navigator.app.exitApp();
});
}, false);
history.subscribe(function () {
alert('Navigated, current url:' + history.href());
});