YuJian920
3 years ago
8 changed files with 75 additions and 10 deletions
@ -0,0 +1,26 @@ |
|||||||
|
import { useMemo } from "react"; |
||||||
|
import { URLSearchParamsInit, useSearchParams } from "react-router-dom"; |
||||||
|
import { cleanObject } from "../utils"; |
||||||
|
|
||||||
|
const useUrlQueryParams = <K extends string>(keys: K[]) => { |
||||||
|
const [searchParams, setSearchParams] = useSearchParams(); |
||||||
|
return [ |
||||||
|
useMemo( |
||||||
|
() => |
||||||
|
keys.reduce( |
||||||
|
(prev, key) => ({ |
||||||
|
...prev, |
||||||
|
[key]: searchParams.get(key) || "", |
||||||
|
}), |
||||||
|
{} as { [key in K]: string } |
||||||
|
), |
||||||
|
[searchParams] |
||||||
|
), |
||||||
|
(params: Partial<{ [key in K]: unknown }>) => { |
||||||
|
const newParams = cleanObject({ ...Object.fromEntries(searchParams), ...params }) as URLSearchParamsInit |
||||||
|
setSearchParams(newParams) |
||||||
|
}, |
||||||
|
] as const; |
||||||
|
}; |
||||||
|
|
||||||
|
export default useUrlQueryParams; |
@ -0,0 +1,7 @@ |
|||||||
|
import React from "react"; |
||||||
|
|
||||||
|
const Kanban = () => { |
||||||
|
return <div>Kanban</div>; |
||||||
|
}; |
||||||
|
|
||||||
|
export default Kanban; |
@ -0,0 +1,7 @@ |
|||||||
|
import React from "react"; |
||||||
|
|
||||||
|
const Task = () => { |
||||||
|
return <div>Task</div>; |
||||||
|
}; |
||||||
|
|
||||||
|
export default Task; |
@ -1,7 +1,25 @@ |
|||||||
import React from 'react' |
import React from "react"; |
||||||
|
import { Routes, Route, Navigate } from "react-router"; |
||||||
|
import { Link } from "react-router-dom"; |
||||||
|
import Kanban from "./Kanban"; |
||||||
|
import Task from "./Task"; |
||||||
|
|
||||||
const Project = () => { |
const Project = () => { |
||||||
return <div>Project</div> |
return ( |
||||||
} |
<div> |
||||||
|
<h1>Project</h1> |
||||||
|
<Link to="kanban">看板</Link> |
||||||
|
<Link to="task">任务组</Link> |
||||||
|
<Routes> |
||||||
|
<Route path="/kanban" element={<Kanban />} /> |
||||||
|
<Route path="/task" element={<Task />} /> |
||||||
|
<Route |
||||||
|
path="*" |
||||||
|
element={<Navigate to={window.location.pathname + "/kanban"} />} |
||||||
|
/> |
||||||
|
</Routes> |
||||||
|
</div> |
||||||
|
); |
||||||
|
}; |
||||||
|
|
||||||
export default Project |
export default Project; |
||||||
|
Loading…
Reference in new issue