mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-07 19:15:05 +08:00
Refactor: UmiJs -> Vite (#12410)
### What problem does this PR solve? Refactor: UmiJs -> Vite+React ### Type of change - [x] Refactoring --------- Co-authored-by: Liu An <asiro@qq.com>
This commit is contained in:
@ -59,5 +59,6 @@ export default storage;
|
||||
|
||||
// Will not jump to the login page
|
||||
export function redirectToLogin() {
|
||||
window.location.href = location.origin + `/login`;
|
||||
const env = import.meta.env;
|
||||
window.location.href = location.origin + env.VITE_BASE_URL + `/login`;
|
||||
}
|
||||
|
||||
125
web/src/utils/simple-history-util.ts
Normal file
125
web/src/utils/simple-history-util.ts
Normal file
@ -0,0 +1,125 @@
|
||||
class GlobalHistory {
|
||||
private listeners: Array<(location: any, action: string) => void> = [];
|
||||
state: any;
|
||||
|
||||
constructor() {
|
||||
window.addEventListener('popstate', this.handlePopState);
|
||||
}
|
||||
|
||||
private handlePopState = (event: PopStateEvent) => {
|
||||
const location = {
|
||||
pathname: window.location.pathname,
|
||||
search: window.location.search,
|
||||
hash: window.location.hash,
|
||||
state: event.state,
|
||||
};
|
||||
|
||||
this.listeners.forEach((listener) => {
|
||||
listener(location, 'POP');
|
||||
});
|
||||
};
|
||||
|
||||
push = (
|
||||
path:
|
||||
| string
|
||||
| { pathname?: string; search?: string; hash?: string; state?: any },
|
||||
state?: any,
|
||||
) => {
|
||||
let finalPath = '';
|
||||
if (typeof path === 'string') {
|
||||
finalPath = path;
|
||||
} else {
|
||||
finalPath = path.pathname || '';
|
||||
if (path.search) finalPath += path.search;
|
||||
if (path.hash) finalPath += path.hash;
|
||||
}
|
||||
|
||||
window.history.pushState(state, '', finalPath);
|
||||
|
||||
const location = {
|
||||
pathname: window.location.pathname,
|
||||
search: window.location.search,
|
||||
hash: window.location.hash,
|
||||
state: state,
|
||||
};
|
||||
|
||||
this.listeners.forEach((listener) => {
|
||||
listener(location, 'PUSH');
|
||||
});
|
||||
};
|
||||
|
||||
replace = (
|
||||
path:
|
||||
| string
|
||||
| { pathname?: string; search?: string; hash?: string; state?: any },
|
||||
state?: any,
|
||||
) => {
|
||||
let finalPath = '';
|
||||
if (typeof path === 'string') {
|
||||
finalPath = path;
|
||||
} else {
|
||||
finalPath = path.pathname || '';
|
||||
if (path.search) finalPath += path.search;
|
||||
if (path.hash) finalPath += path.hash;
|
||||
}
|
||||
|
||||
window.history.replaceState(state, '', finalPath);
|
||||
|
||||
const location = {
|
||||
pathname: window.location.pathname,
|
||||
search: window.location.search,
|
||||
hash: window.location.hash,
|
||||
state: state,
|
||||
};
|
||||
|
||||
this.listeners.forEach((listener) => {
|
||||
listener(location, 'REPLACE');
|
||||
});
|
||||
};
|
||||
|
||||
go = (n: number) => {
|
||||
window.history.go(n);
|
||||
};
|
||||
|
||||
goBack = () => {
|
||||
window.history.back();
|
||||
};
|
||||
|
||||
goForward = () => {
|
||||
window.history.forward();
|
||||
};
|
||||
|
||||
listen = (callback: (location: any, action: string) => void) => {
|
||||
this.listeners.push(callback);
|
||||
|
||||
return () => {
|
||||
const index = this.listeners.indexOf(callback);
|
||||
if (index !== -1) {
|
||||
this.listeners.splice(index, 1);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
get location() {
|
||||
return {
|
||||
pathname: window.location.pathname,
|
||||
search: window.location.search,
|
||||
hash: window.location.hash,
|
||||
state: history.state,
|
||||
};
|
||||
}
|
||||
|
||||
get length() {
|
||||
return window.history.length;
|
||||
}
|
||||
|
||||
get action() {
|
||||
return 'POP';
|
||||
}
|
||||
}
|
||||
|
||||
export const history = new GlobalHistory();
|
||||
|
||||
export const useCustomNavigate = () => {
|
||||
return history;
|
||||
};
|
||||
Reference in New Issue
Block a user