Replace history.pushState with svelte pushState

This commit is contained in:
freearhey 2025-03-08 01:21:02 +03:00
parent 627ea95ec9
commit b8e45bcd98
2 changed files with 11 additions and 11 deletions

View file

@ -8,6 +8,7 @@
import ClosedBadge from './ClosedBadge.svelte' import ClosedBadge from './ClosedBadge.svelte'
import { downloadMode, selected } from '~/store' import { downloadMode, selected } from '~/store'
import { fade } from 'svelte/transition' import { fade } from 'svelte/transition'
import { pushState } from '$app/navigation'
export let channel export let channel
@ -21,10 +22,10 @@
let prevUrl = '/' let prevUrl = '/'
const onOpened = () => { const onOpened = () => {
prevUrl = window.location.href prevUrl = window.location.href
window.history.pushState({}, `${displayName} • iptv-org`, `/channels/${country}/${name}`) pushState(`/channels/${country}/${name}`, {})
} }
const onClose = () => { const onClose = () => {
window.history.pushState({}, `iptv-org`, prevUrl) pushState(prevUrl, {})
} }
const showGuides = () => const showGuides = () =>
open( open(

View file

@ -4,6 +4,7 @@ import sj from '@freearhey/search-js'
import _ from 'lodash' import _ from 'lodash'
import { browser } from '$app/environment' import { browser } from '$app/environment'
import { Channel } from './models' import { Channel } from './models'
import { pushState } from '$app/navigation'
export const query = writable('') export const query = writable('')
export const hasQuery = writable(false) export const hasQuery = writable(false)
@ -68,15 +69,13 @@ export async function fetchChannels() {
} }
export function setSearchParam(key, value) { export function setSearchParam(key, value) {
if (window.history.pushState) { let query = key && value ? `?${key}=${value}` : ''
let query = key && value ? `?${key}=${value}` : '' query = query.replace(/\+/g, '%2B')
query = query.replace(/\+/g, '%2B') const url = `${window.location.protocol}//${window.location.host}${window.location.pathname}${query}`
const url = `${window.location.protocol}//${window.location.host}${window.location.pathname}${query}` const state = {}
const state = {} state[key] = value
state[key] = value pushState(url, state)
window.history.pushState(state, '', url) setPageTitle(value)
setPageTitle(value)
}
} }
export function setPageTitle(value) { export function setPageTitle(value) {