Skip to content

Commit 4e570ce

Browse files
committed
feat: useRouter支持加入参数query
1 parent 47e4a14 commit 4e570ce

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/features/router/router.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { store } from '@/store';
66

77
import { getIsLogin } from '../auth/authStore';
88

9+
import { type LocationQueryRaw, stringifyQuery } from './query';
910
import { initAuthRoutes } from './routerHooks';
1011

1112
function initRouter() {
@@ -88,13 +89,26 @@ export function navigator() {
8889
reactRouter.navigate('/');
8990
}
9091

92+
function push(path: string, query?: LocationQueryRaw, state?: any) {
93+
let _path = path;
94+
95+
if (query) {
96+
const search = stringifyQuery(query);
97+
98+
_path = `${path}?${search}`;
99+
}
100+
101+
reactRouter.navigate(_path, { state });
102+
}
103+
91104
return {
92105
back,
93106
forward,
94107
go,
95108
goHome,
96109
navigate,
97110
navigateUp,
111+
push,
98112
reactRouter,
99113
reload,
100114
replace

0 commit comments

Comments
 (0)