client: keep router query

This commit is contained in:
fantasticit 2022-06-03 15:39:44 +08:00
parent 5b6f211900
commit 778217022a
3 changed files with 19 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import { useRouter } from 'next/router';
import { Router, useRouter } from 'next/router';
export function useRouterQuery<T>() {
export function useRouterQuery<T extends Router['query']>() {
const router = useRouter();
return router.query as unknown as T;
return router.query as T;
}

View File

@ -3,6 +3,7 @@ import { Author } from 'components/author';
import { LogoImage, LogoText } from 'components/logo';
import { Seo } from 'components/seo';
import { useUser } from 'data/user';
import { useRouterQuery } from 'hooks/use-router-query';
import { useToggle } from 'hooks/use-toggle';
import Link from 'next/link';
import React, { useCallback } from 'react';
@ -14,6 +15,7 @@ const { Title, Text } = Typography;
const Page = () => {
const { login } = useUser();
const query = useRouterQuery();
const [loading, toggleLoading] = useToggle(false);
const toLogin = useCallback(
@ -66,7 +68,12 @@ const Page = () => {
</Button>
<footer>
<Text link style={{ textAlign: 'center' }}>
<Link href="/register">
<Link
href={{
pathname: '/register',
query,
}}
>
<a></a>
</Link>
</Text>

View File

@ -3,6 +3,7 @@ import { Author } from 'components/author';
import { LogoImage, LogoText } from 'components/logo';
import { Seo } from 'components/seo';
import { useAsyncLoading } from 'hooks/use-async-loading';
import { useRouterQuery } from 'hooks/use-router-query';
import Link from 'next/link';
import Router from 'next/router';
import React from 'react';
@ -14,6 +15,7 @@ const { Content, Footer } = Layout;
const { Title, Text } = Typography;
const Page = () => {
const query = useRouterQuery();
const [registerWithLoading, loading] = useAsyncLoading(registerApi);
const onFinish = (values) => {
@ -75,7 +77,12 @@ const Page = () => {
</Button>
<footer>
<Text link style={{ textAlign: 'center' }}>
<Link href="/login">
<Link
href={{
pathname: '/login',
query,
}}
>
<a>使</a>
</Link>
</Text>