diff --git a/src/routes/MetaDetails/EpisodePicker/EpisodePicker.tsx b/src/routes/MetaDetails/EpisodePicker/EpisodePicker.tsx index 256c827a9..d00429638 100644 --- a/src/routes/MetaDetails/EpisodePicker/EpisodePicker.tsx +++ b/src/routes/MetaDetails/EpisodePicker/EpisodePicker.tsx @@ -16,6 +16,10 @@ const EpisodePicker = ({ className, onSubmit }: Props) => { const { initialSeason, initialEpisode } = useMemo(() => { const splitPath = window.location.hash.split('/'); + if (splitPath[splitPath.length - 1] === '') { + // remove the empty element + splitPath.pop(); + } const videoId = decodeURIComponent(splitPath[splitPath.length - 1]); const [, pathSeason, pathEpisode] = videoId ? videoId.split(':') : []; return { diff --git a/src/routes/MetaDetails/MetaDetails.js b/src/routes/MetaDetails/MetaDetails.js index fd27478b5..16b20a28b 100644 --- a/src/routes/MetaDetails/MetaDetails.js +++ b/src/routes/MetaDetails/MetaDetails.js @@ -81,7 +81,11 @@ const MetaDetails = ({ urlParams, queryParams }) => { const handleEpisodeSearch = React.useCallback((season, episode) => { const searchVideoHash = encodeURIComponent(`${urlParams.id}:${season}:${episode}`); const url = window.location.hash; - const searchVideoPath = url.replace(encodeURIComponent(urlParams.videoId), searchVideoHash); + + const searchVideoPath = (urlParams.videoId === undefined || urlParams.videoId === null || urlParams.videoId === '') ? + url + (!url.endsWith('/') ? '/' : '') + searchVideoHash + : url.replace(encodeURIComponent(urlParams.videoId), searchVideoHash); + window.location = searchVideoPath; }, [urlParams, window.location]); diff --git a/src/routes/MetaDetails/useMetaDetails.js b/src/routes/MetaDetails/useMetaDetails.js index c3790fddb..f86259345 100644 --- a/src/routes/MetaDetails/useMetaDetails.js +++ b/src/routes/MetaDetails/useMetaDetails.js @@ -48,7 +48,7 @@ const useMetaDetails = (urlParams) => { id: urlParams.id, extra: [] }, - streamPath: typeof urlParams.videoId === 'string' ? + streamPath: typeof urlParams.videoId === 'string' && urlParams.videoId !== '' ? { resource: 'stream', type: urlParams.type, diff --git a/src/routes/MetaDetails/useSeason.js b/src/routes/MetaDetails/useSeason.js index 9d958a5cf..ec310c656 100644 --- a/src/routes/MetaDetails/useSeason.js +++ b/src/routes/MetaDetails/useSeason.js @@ -12,7 +12,12 @@ const useSeason = (urlParams, queryParams) => { const setSeason = React.useCallback((season) => { const nextQueryParams = new URLSearchParams(queryParams); nextQueryParams.set('season', season); - window.location.replace(`#${urlParams.path}?${nextQueryParams}`); + const path = urlParams.path.endsWith('/') ? + // remove the trailing / + urlParams.path.slice(0, -1): + urlParams.path; + + window.location.replace(`#${path}?${nextQueryParams}`); }, [urlParams, queryParams]); return [season, setSeason]; };