Skip to content

Commit

Permalink
Decouple / proper navigation for base_url
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhlongviolin1 committed Aug 7, 2024
1 parent 8c475fb commit 39da1d1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions frontend/taipy-gui/base/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class TaipyApp {
path: string | undefined = undefined,
socket: Socket | undefined = undefined,
) {
socket = socket || io("/", { autoConnect: false, path: `${getBase()}socket.io` });
socket = socket || io("/", { autoConnect: false, path: `${this.getBaseUrl()}socket.io` });
this.onInit = onInit;
this.onChange = onChange;
this.variableData = undefined;
Expand Down Expand Up @@ -232,7 +232,7 @@ export class TaipyApp {

updateContext(path: string | undefined = "") {
if (!path || path === "") {
path = window.location.pathname.slice(1);
path = window.location.pathname.replace(this.getBaseUrl().slice(0, -1), "") || "/"
}
this.sendWsMessage("GMC", "get_module_context", { path: path || "/" });
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/taipy-gui/base/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const getBase = () => {
return document.getElementsByTagName("base")[0].getAttribute("href");
return document.getElementsByTagName("base")[0].getAttribute("href") || "/";
};
6 changes: 4 additions & 2 deletions frontend/taipy-gui/src/components/Taipy/Navigate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useContext, useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { TaipyContext } from "../../context/taipyContext";
import { createNavigateAction } from "../../context/taipyReducers";
import { getBaseURL } from "../../utils";

interface NavigateProps {
to?: string;
Expand All @@ -32,6 +33,7 @@ const Navigate = ({ to, params, tab, force }: NavigateProps) => {
useEffect(() => {
if (to) {
const tos = to === "/" ? to : "/" + to;
const navigatePath = getBaseURL() + tos.slice(1)
const filteredParams = params
? Object.keys(params).reduce((acc, key) => {
if (!SPECIAL_PARAMS.includes(key)) {
Expand All @@ -56,10 +58,10 @@ const Navigate = ({ to, params, tab, force }: NavigateProps) => {
// Regular navigate cases
if (Object.keys(state.locations || {}).some((route) => tos === route)) {
const searchParamsLocation = new URLSearchParams(location.search);
if (force && location.pathname === tos && searchParamsLocation.toString() === searchParams.toString()) {
if (force && location.pathname === navigatePath && searchParamsLocation.toString() === searchParams.toString()) {
navigate(0);
} else {
navigate({ pathname: to, search: `?${searchParams.toString()}` });
navigate({ pathname: navigatePath, search: `?${searchParams.toString()}` });
// Handle Resource Handler Id
const tprh = params?.tprh;
if (tprh !== undefined) {
Expand Down

0 comments on commit 39da1d1

Please sign in to comment.