-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5827 from thornbill/router-v13-unstable
- Loading branch information
Showing
10 changed files
with
132 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React, { useMemo } from 'react'; | ||
import { Navigate, useLocation } from 'react-router-dom'; | ||
|
||
const BangRedirect = () => { | ||
const location = useLocation(); | ||
|
||
const to = useMemo(() => { | ||
const _to = { | ||
search: location.search, | ||
hash: location.hash | ||
}; | ||
|
||
if (location.pathname.startsWith('/!/')) { | ||
return { ..._to, pathname: location.pathname.substring(2) }; | ||
} else if (location.pathname.startsWith('/!')) { | ||
return { ..._to, pathname: location.pathname.replace(/^\/!/, '/') }; | ||
} else if (location.pathname.startsWith('!')) { | ||
return { ..._to, pathname: location.pathname.substring(1) }; | ||
} | ||
}, [ location ]); | ||
|
||
if (!to) return null; | ||
|
||
console.warn('[BangRedirect] You are using a deprecated URL format. This will stop working in a future Jellyfin update.'); | ||
|
||
return ( | ||
<Navigate | ||
replace | ||
to={to} | ||
/> | ||
); | ||
}; | ||
|
||
export default BangRedirect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import type { Router, RouterState } from '@remix-run/router'; | ||
import type { History, Listener, To } from 'history'; | ||
|
||
import Events, { type Event } from 'utils/events'; | ||
|
||
const HISTORY_UPDATE_EVENT = 'HISTORY_UPDATE'; | ||
|
||
export class RouterHistory implements History { | ||
_router: Router; | ||
createHref: (arg: any) => string; | ||
|
||
constructor(router: Router) { | ||
this._router = router; | ||
|
||
this._router.subscribe(state => { | ||
console.debug('[RouterHistory] history update', state); | ||
Events.trigger(document, HISTORY_UPDATE_EVENT, [ state ]); | ||
}); | ||
|
||
this.createHref = router.createHref; | ||
} | ||
|
||
get action() { | ||
return this._router.state.historyAction; | ||
} | ||
|
||
get location() { | ||
return this._router.state.location; | ||
} | ||
|
||
back() { | ||
void this._router.navigate(-1); | ||
} | ||
|
||
forward() { | ||
void this._router.navigate(1); | ||
} | ||
|
||
go(delta: number) { | ||
void this._router.navigate(delta); | ||
} | ||
|
||
push(to: To, state?: any) { | ||
void this._router.navigate(to, { state }); | ||
} | ||
|
||
replace(to: To, state?: any): void { | ||
void this._router.navigate(to, { state, replace: true }); | ||
} | ||
|
||
block() { | ||
// NOTE: We don't seem to use this functionality, so leaving it unimplemented. | ||
throw new Error('`history.block()` is not implemented'); | ||
return () => undefined; | ||
} | ||
|
||
listen(listener: Listener) { | ||
const compatListener = (_e: Event, state: RouterState) => { | ||
return listener({ action: state.historyAction, location: state.location }); | ||
}; | ||
|
||
Events.on(document, HISTORY_UPDATE_EVENT, compatListener); | ||
|
||
return () => Events.off(document, HISTORY_UPDATE_EVENT, compatListener); | ||
} | ||
} | ||
|
||
export const createRouterHistory = (router: Router): History => { | ||
return new RouterHistory(router); | ||
}; | ||
|
||
/* eslint-enable @typescript-eslint/no-explicit-any */ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters