update(redirect): 期刊详情跳转移动端

feature/artists
mackt 7 months ago
parent 80b01e0826
commit d6b4f7531e

@ -1,5 +1,5 @@
/** 期刊详情 */
import { notFound } from 'next/navigation';
import { notFound, redirect, RedirectType } from 'next/navigation';
import { SongCardList, JournalRecommendList, Comment, CollectButton, VolDetailCoverCard } from '@/components';
import { apiGetJournalInfoById, apiGetSongsByJournalNo, apiGetJournalRecommendById } from '@/services';
@ -20,9 +20,19 @@ const getData = async (journalId: string) => {
return { journalInfo: journalInfoRes.data, songList: songListRes.data, recommendList: recommendList.data };
};
export default async function JournalDetail({ params: { journalId } }: { params: { journalId: string } }) {
export default async function JournalDetail({
params: { journalId },
searchParams: { mobile },
}: {
params: { journalId: string };
searchParams: { mobile: string };
}) {
const { journalInfo, songList, recommendList } = await getData(journalId);
if (mobile) {
redirect(`${process.env.NEXT_PUBLIC_MOBILE_HOST}/html/journal.html?id=${journalInfo.id}`, RedirectType.replace);
}
return (
<main className="w-[1200px] mx-auto flex flex-row justify-between pt-[145px]">
<div className="w-[712px]">

@ -3,13 +3,18 @@ import { NextResponse, userAgent } from 'next/server';
import type { NextRequest } from 'next/server';
export async function middleware(request: NextRequest) {
const { pathname, origin, basePath } = request.nextUrl;
const { href, pathname, searchParams, origin, basePath } = request.nextUrl;
if (searchParams.get('next')) {
return NextResponse.next();
}
// 跳转移动端
const { device } = userAgent(request);
const isMobile = device.type && ['mobile', 'tablet'].includes(device.type);
if (isMobile) {
return NextResponse.redirect(`${process.env.NEXT_PUBLIC_MOBILE_HOST}/index.html`);
if (isMobile && request.nextUrl.pathname.startsWith('/vol')) {
const redirectUrl: URL = new URL(`${href}?next=1&mobile=1`);
return NextResponse.redirect(redirectUrl, 307);
}
// 鉴权
@ -34,5 +39,5 @@ export async function middleware(request: NextRequest) {
}
export const config = {
matcher: ['/:path*'],
matcher: ['/vol/:path*', '/my/:path*'],
};

Loading…
Cancel
Save