Skip to content

Commit

Permalink
chore: Fix the url redirect issue for Standalone mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jessieweiyi committed Jun 16, 2024
1 parent 080ccbe commit 3cdfd1c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
See the License for the specific language governing permissions and
limitations under the License.
******************************************************************************************************************** */
import { FC } from 'react';
import { FC, useState } from 'react';
import { RouterProvider } from 'react-router-dom';
import router from '../../../../routes';
import { routerOpts, createRouter, routes } from '../../../../routes';

const Full: FC = () => {
const [router] = useState(() => {
//Initialize here to ensure the default index loader only call when Full is mount without affecting Standalone mode
return createRouter(routes, routerOpts);
});

return (
<RouterProvider router={router} />
);
Expand Down
10 changes: 4 additions & 6 deletions packages/threat-composer-app/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ const workspaceRoutes = [
},
];

const createRouter = isMemoryRouterUsed() ? createMemoryRouter : createBrowserRouter;
export const createRouter = isMemoryRouterUsed() ? createMemoryRouter : createBrowserRouter;

const opts = ROUTE_BASE_PATH ? {
export const routerOpts = ROUTE_BASE_PATH ? {
basename: ROUTE_BASE_PATH,
} : {};

const router = createRouter([
export const routes = [
{
index: true,
loader: initialWorkspaceLoader,
Expand All @@ -139,6 +139,4 @@ const router = createRouter([
},
],
},
], opts);

export default router;
];
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const WorkspacesLocalStateContextProvider: FC<WorkspacesContextProviderProps> =
}) => {
const { workspaceExamples } = useWorkspaceExamplesContext();

const [workspaceList, setWorkspaceList] = useState<Workspace[]>([]);

const [currentWorkspace, setCurrentWorkspace] = useState<Workspace | null>(() => {
if (workspaceName) { // If the workspaceName is specified by outside scope (e.g. Url), return the workspace specified by the id
if (workspaceName === DEFAULT_WORKSPACE_ID) {
Expand All @@ -49,8 +51,6 @@ const WorkspacesLocalStateContextProvider: FC<WorkspacesContextProviderProps> =
return null;
});

const [workspaceList, setWorkspaceList] = useState<Workspace[]>([]);

const {
handleSwitchWorkspace,
handleAddWorkspace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const WorkspacesLocalStorageContextProvider: FC<WorkspacesContextProviderProps>
}

return lastWorkspace;
}, [lastWorkspace, workspaceName, workspaceExamples]);
}, [lastWorkspace, workspaceName, workspaceExamples, workspaceList]);

const {
handleSwitchWorkspace,
Expand Down

0 comments on commit 3cdfd1c

Please sign in to comment.