瀏覽代碼

Decouple / proper navigation for base_url (#1643)

Dinh Long Nguyen 9 月之前
父節點
當前提交
6fa0903bde

+ 2 - 2
frontend/taipy-gui/base/src/app.ts

@@ -49,7 +49,7 @@ export class TaipyApp {
         path: string | undefined = undefined,
         path: string | undefined = undefined,
         socket: Socket | 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.onInit = onInit;
         this.onChange = onChange;
         this.onChange = onChange;
         this.variableData = undefined;
         this.variableData = undefined;
@@ -232,7 +232,7 @@ export class TaipyApp {
 
 
     updateContext(path: string | undefined = "") {
     updateContext(path: string | undefined = "") {
         if (!path || path === "") {
         if (!path || path === "") {
-            path = window.location.pathname.slice(1);
+            path = window.location.pathname.replace(this.getBaseUrl(), "") || "/"
         }
         }
         this.sendWsMessage("GMC", "get_module_context", { path: path || "/" });
         this.sendWsMessage("GMC", "get_module_context", { path: path || "/" });
     }
     }

+ 1 - 1
frontend/taipy-gui/base/src/utils.ts

@@ -1,3 +1,3 @@
 export const getBase = () => {
 export const getBase = () => {
-    return document.getElementsByTagName("base")[0].getAttribute("href");
+    return document.getElementsByTagName("base")[0].getAttribute("href") || "/";
 };
 };

+ 4 - 2
frontend/taipy-gui/src/components/Taipy/Navigate.tsx

@@ -15,6 +15,7 @@ import { useContext, useEffect } from "react";
 import { useLocation, useNavigate } from "react-router-dom";
 import { useLocation, useNavigate } from "react-router-dom";
 import { TaipyContext } from "../../context/taipyContext";
 import { TaipyContext } from "../../context/taipyContext";
 import { createNavigateAction } from "../../context/taipyReducers";
 import { createNavigateAction } from "../../context/taipyReducers";
+import { getBaseURL } from "../../utils";
 
 
 interface NavigateProps {
 interface NavigateProps {
     to?: string;
     to?: string;
@@ -32,6 +33,7 @@ const Navigate = ({ to, params, tab, force }: NavigateProps) => {
     useEffect(() => {
     useEffect(() => {
         if (to) {
         if (to) {
             const tos = to === "/" ? to : "/" + to;
             const tos = to === "/" ? to : "/" + to;
+            const navigatePath = getBaseURL() + tos.slice(1)
             const filteredParams = params
             const filteredParams = params
                 ? Object.keys(params).reduce((acc, key) => {
                 ? Object.keys(params).reduce((acc, key) => {
                       if (!SPECIAL_PARAMS.includes(key)) {
                       if (!SPECIAL_PARAMS.includes(key)) {
@@ -56,10 +58,10 @@ const Navigate = ({ to, params, tab, force }: NavigateProps) => {
             // Regular navigate cases
             // Regular navigate cases
             if (Object.keys(state.locations || {}).some((route) => tos === route)) {
             if (Object.keys(state.locations || {}).some((route) => tos === route)) {
                 const searchParamsLocation = new URLSearchParams(location.search);
                 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);
                     navigate(0);
                 } else {
                 } else {
-                    navigate({ pathname: to, search: `?${searchParams.toString()}` });
+                    navigate({ pathname: navigatePath, search: `?${searchParams.toString()}` });
                     // Handle Resource Handler Id
                     // Handle Resource Handler Id
                     const tprh = params?.tprh;
                     const tprh = params?.tprh;
                     if (tprh !== undefined) {
                     if (tprh !== undefined) {