mirror of https://github.com/fantasticit/think.git
client: keep router query
This commit is contained in:
parent
5b6f211900
commit
778217022a
|
@ -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();
|
const router = useRouter();
|
||||||
return router.query as unknown as T;
|
return router.query as T;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { Author } from 'components/author';
|
||||||
import { LogoImage, LogoText } from 'components/logo';
|
import { LogoImage, LogoText } from 'components/logo';
|
||||||
import { Seo } from 'components/seo';
|
import { Seo } from 'components/seo';
|
||||||
import { useUser } from 'data/user';
|
import { useUser } from 'data/user';
|
||||||
|
import { useRouterQuery } from 'hooks/use-router-query';
|
||||||
import { useToggle } from 'hooks/use-toggle';
|
import { useToggle } from 'hooks/use-toggle';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import React, { useCallback } from 'react';
|
import React, { useCallback } from 'react';
|
||||||
|
@ -14,6 +15,7 @@ const { Title, Text } = Typography;
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
const { login } = useUser();
|
const { login } = useUser();
|
||||||
|
const query = useRouterQuery();
|
||||||
const [loading, toggleLoading] = useToggle(false);
|
const [loading, toggleLoading] = useToggle(false);
|
||||||
|
|
||||||
const toLogin = useCallback(
|
const toLogin = useCallback(
|
||||||
|
@ -66,7 +68,12 @@ const Page = () => {
|
||||||
</Button>
|
</Button>
|
||||||
<footer>
|
<footer>
|
||||||
<Text link style={{ textAlign: 'center' }}>
|
<Text link style={{ textAlign: 'center' }}>
|
||||||
<Link href="/register">
|
<Link
|
||||||
|
href={{
|
||||||
|
pathname: '/register',
|
||||||
|
query,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<a>注册用户以登录</a>
|
<a>注册用户以登录</a>
|
||||||
</Link>
|
</Link>
|
||||||
</Text>
|
</Text>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { Author } from 'components/author';
|
||||||
import { LogoImage, LogoText } from 'components/logo';
|
import { LogoImage, LogoText } from 'components/logo';
|
||||||
import { Seo } from 'components/seo';
|
import { Seo } from 'components/seo';
|
||||||
import { useAsyncLoading } from 'hooks/use-async-loading';
|
import { useAsyncLoading } from 'hooks/use-async-loading';
|
||||||
|
import { useRouterQuery } from 'hooks/use-router-query';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import Router from 'next/router';
|
import Router from 'next/router';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
@ -14,6 +15,7 @@ const { Content, Footer } = Layout;
|
||||||
const { Title, Text } = Typography;
|
const { Title, Text } = Typography;
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
|
const query = useRouterQuery();
|
||||||
const [registerWithLoading, loading] = useAsyncLoading(registerApi);
|
const [registerWithLoading, loading] = useAsyncLoading(registerApi);
|
||||||
|
|
||||||
const onFinish = (values) => {
|
const onFinish = (values) => {
|
||||||
|
@ -75,7 +77,12 @@ const Page = () => {
|
||||||
</Button>
|
</Button>
|
||||||
<footer>
|
<footer>
|
||||||
<Text link style={{ textAlign: 'center' }}>
|
<Text link style={{ textAlign: 'center' }}>
|
||||||
<Link href="/login">
|
<Link
|
||||||
|
href={{
|
||||||
|
pathname: '/login',
|
||||||
|
query,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<a>使用其他账户登录</a>
|
<a>使用其他账户登录</a>
|
||||||
</Link>
|
</Link>
|
||||||
</Text>
|
</Text>
|
||||||
|
|
Loading…
Reference in New Issue