/
githubmirror
/
ionic
Обзор
Документация
Войти
/
githubmirror
/
ionic
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/react-router/test/base/src/utils/LocationHistory.ts
45 строк
1 KB
Liam DeBeasi
test(react-router): migrate to builder architecture (#26961)
18 мар 2023, 00:13
Не верифицирован
18 мар 2023, 00:13
115f2b5
Код
Авторство
О чём код?
import { Location as HistoryLocation } from 'history'; const RESTRICT_SIZE = 25; export class LocationHistory { private locationHistory: HistoryLocation[] = []; add(location: HistoryLocation) { this.locationHistory.push(location); if (this.locationHistory.length > RESTRICT_SIZE) { this.locationHistory.splice(0, 10); } } pop() { this.locationHistory.pop(); } replace(location: HistoryLocation) { this.locationHistory.pop(); this.locationHistory.push(location); } clear() { this.locationHistory = []; } findLastLocationByUrl(url: string) { for (let i = this.locationHistory.length - 1; i >= 0; i--) { const location = this.locationHistory[i]; if (location.pathname.toLocaleLowerCase() === url.toLocaleLowerCase()) { return location; } } return undefined; } previous() { return this.locationHistory[this.locationHistory.length - 2]; } current() { return this.locationHistory[this.locationHistory.length - 1]; } }