I’ve followed the redirections doc from Redirections with Frontity - Frontity Docs and decided to use the alternative usage method. To do this, i have a post handler that checks whether a route is required to be redirected. If it is, then we set the state.source.data[route]
to the redirect data object. The code snippets are shown below:
// redirect post
if (state.source.redirectionsData) {
const redirect = getRedirect(route, state.source.redirectionsData);
if (redirect) {
state.source.data[route] = state.source.redirectionsData[redirect];
return;
}
}
This is how the redirect data object is
const getRedirectionData = (route: string) => {
const destination = redirectionsMap[route];
return {
isReady: true,
isRedirection: true,
is301: true,
redirectionStatus: 301,
isExternal: true,
location: destination,
};
};
The issue i have with this is that is does not work when the destination website is an external site i.e. when isExternal = true, there will be an illegal invocation error when redirecting on the client side as shown below.
The error is specifically on the line window.replaceLocation(data.location)
in tiny-router/src/actions.ts
snippet below.
// If the data is a redirection, then we set the link to the location.
// The redirections are stored in source.data just like any other data.
const data = state.source?.get(link);
if (data && data.isReady && isRedirection(data)) {
if (data.isExternal) {
window.replaceLocation(data.location); <--- This line errors
} else {
// If the link is internal, we have to discard the domain.
I have also checked that the data object for the route to redirect is correctly set when checking on browser console on frontity.state.source.data
:
/safety/.../:
is301: true
isExternal: true
isFetching: false
isReady: true
isRedirection: true
link: "/safety/.../"
location: "https://www.externalSite.com"
page: 1
query: {}
redirectionStatus: 301
route: "/safety/.../"
Some clarifications:
When isExternal = false, both server and client redirect works.
When isExternal = true, only server redirect works, client redirect does not work.
Is this a bug on tiny-router or did i do something wrong here?