This is an automated email from the ASF dual-hosted git repository.
shuai pushed a commit to branch feat/baseurl
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
The following commit(s) were added to refs/heads/feat/baseurl by this push:
new 571c2b1a fix: naviage add base path
571c2b1a is described below
commit 571c2b1a19d6d2c29bc1cfed52a44b9cbab91d75
Author: shuai <[email protected]>
AuthorDate: Tue Mar 26 10:47:46 2024 +0800
fix: naviage add base path
---
ui/src/utils/floppyNavigation.ts | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/ui/src/utils/floppyNavigation.ts b/ui/src/utils/floppyNavigation.ts
index 308d2fac..30be62ca 100644
--- a/ui/src/utils/floppyNavigation.ts
+++ b/ui/src/utils/floppyNavigation.ts
@@ -19,7 +19,7 @@
import type { NavigateFunction } from 'react-router-dom';
-import { RouteAlias } from '@/router/alias';
+import { RouteAlias, REACT_BASE_PATH } from '@/router/alias';
import Storage from '@/utils/storage';
import { REDIRECT_PATH_STORAGE_KEY } from '@/common/constants';
import { getLoginUrl } from '@/utils/userCenter';
@@ -133,8 +133,22 @@ const navigate = (to: string | number, config:
NavigateConfig = {}) => {
handler = 'replace';
}
if (handler === 'href') {
+ if (
+ to.startsWith('/') &&
+ !to.startsWith('//') &&
+ !to.startsWith(REACT_BASE_PATH)
+ ) {
+ to = `${REACT_BASE_PATH}${to}`;
+ }
window.location.href = to;
} else if (handler === 'replace') {
+ if (
+ to.startsWith('/') &&
+ !to.startsWith('//') &&
+ !to.startsWith(REACT_BASE_PATH)
+ ) {
+ to = `${REACT_BASE_PATH}${to}`;
+ }
window.location.replace(to);
} else if (typeof handler === 'function') {
handler(to === '/test' ? '/' : to, config.options);