You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by sh...@apache.org on 2024/06/13 06:53:13 UTC
(incubator-answer) branch fix/edit_profile created (now db4a0efb)
This is an automated email from the ASF dual-hosted git repository.
shuai pushed a change to branch fix/edit_profile
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
at db4a0efb fix: add basepath logic to route jump
This branch includes the following new commits:
new db4a0efb fix: add basepath logic to route jump
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(incubator-answer) 01/01: fix: add basepath logic to route jump
Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
shuai pushed a commit to branch fix/edit_profile
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit db4a0efbef281fc0a814b13fd6d6def77c709555
Author: shuai <li...@sifou.com>
AuthorDate: Thu Jun 13 14:53:02 2024 +0800
fix: add basepath logic to route jump
---
ui/src/utils/floppyNavigation.ts | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/ui/src/utils/floppyNavigation.ts b/ui/src/utils/floppyNavigation.ts
index 69ba4e88..eb06139f 100644
--- a/ui/src/utils/floppyNavigation.ts
+++ b/ui/src/utils/floppyNavigation.ts
@@ -26,16 +26,25 @@ import { getLoginUrl } from '@/utils/userCenter';
const equalToCurrentHref = (target: string, base?: string) => {
base ||= window.location.origin;
- const targetUrl = new URL(target, base);
+ const targetUrl = new URL(
+ target.startsWith(REACT_BASE_PATH) ? target : `${REACT_BASE_PATH}${target}`,
+ base,
+ );
return targetUrl.toString() === window.location.href;
};
const matchToCurrentHref = (target: string) => {
target = (target || '').trim();
+ const hasBasePath = target.startsWith(REACT_BASE_PATH);
// Empty string or `/` can match any path
if (!target || target === '/') {
return true;
}
const { pathname, search, hash } = window.location;
+ let pathWithOutBase = pathname;
+ if (!hasBasePath) {
+ pathWithOutBase = pathWithOutBase.replace(REACT_BASE_PATH, '');
+ }
+
const tPart = target.split('?');
/**
@@ -59,7 +68,7 @@ const matchToCurrentHref = (target: string) => {
*/
let pathMatch = true;
const tPath = tPart[0].split('/').filter((_) => !!_);
- const lPath = pathname.split('/').filter((_) => !!_);
+ const lPath = pathWithOutBase.split('/').filter((_) => !!_);
tPath.forEach((p, i) => {
const lp = lPath[i];
@@ -73,9 +82,10 @@ const matchToCurrentHref = (target: string) => {
const storageLoginRedirect = () => {
const { pathname } = window.location;
- if (pathname !== RouteAlias.login && pathname !== RouteAlias.signUp) {
+ const filterPath = pathname.replace(REACT_BASE_PATH, '');
+ if (filterPath !== RouteAlias.login && filterPath !== RouteAlias.signUp) {
const loc = window.location;
- const redirectUrl = loc.href.replace(loc.origin, '');
+ const redirectUrl = loc.href.replace(`${loc.origin}${REACT_BASE_PATH}`, '');
Storage.set(REDIRECT_PATH_STORAGE_KEY, redirectUrl);
}
};
@@ -151,12 +161,12 @@ const navigate = (to: string | number, config: NavigateConfig = {}) => {
}
window.location.replace(to);
} else if (typeof handler === 'function') {
- if (to === '/test') {
+ if (to === REACT_BASE_PATH) {
to = '/';
}
- if (to !== '/test' && to.startsWith('/test')) {
- to = to.replace('/test', '');
+ if (to !== REACT_BASE_PATH && to.startsWith(REACT_BASE_PATH)) {
+ to = to.replace(REACT_BASE_PATH, '');
}
handler(to, config.options);
}