Skip to content

Commit

Permalink
fix: cannot redirect to last visited location on relaunch
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengjitf committed Dec 28, 2023
1 parent 5dd64dd commit 6e215b0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/insomnia/src/ui/routes/organization.tsx
Expand Up @@ -195,12 +195,18 @@ export const indexLoader: LoaderFunction = async () => {
}
}

if (personalOrganization) {
return redirect(`/organization/${personalOrganization.id}`);
}

if (organizations.length > 0) {
return redirect(`/organization/${organizations[0].id}`);
const organizationId = personalOrganization?.id || organizations?.[0]?.id;
if (organizationId) {
const prevOrganizationLocation = localStorage.getItem(
`locationHistoryEntry:${organizationId}`
);
if (prevOrganizationLocation) {
console.log('Redirecting to last visited location', prevOrganizationLocation);
// Don't check if the resources referenced in location exist, such as project, workspace, etc.
// Leave that to the respective loaders, show more friendly notices and be able to fallback to home page.
return redirect(prevOrganizationLocation);
}
return redirect(`/organization/${organizationId}`);
}
} catch (error) {
console.log('Failed to load Organizations', error);
Expand Down

0 comments on commit 6e215b0

Please sign in to comment.