fix: 路由跳转

main
fadeaway 5 months ago
parent 7364f33785
commit 928d1c2888

@ -3,7 +3,6 @@
import { useRef } from 'react';
import Link from 'next/link';
// import { useRouter } from 'next/navigation';
import AppLogo from '@/components/AppLogo';
import ImageWithBasePath from '@/components/ImageWithBasePath';
@ -11,19 +10,19 @@ import WXShareBtn from '@/components/WXComponent/WXShareBtn';
import { download } from '@/utils/download';
import useNav from '@/hooks/useNav';
import useUA from '@/hooks/useUA';
export default function Home() {
// const router = useRouter();
const firstScreenRef = useRef<HTMLDivElement>(null);
const { inWX } = useUA();
const nav = useNav();
const handleDownload = () => {
if (!inWX) {
download();
} else {
// router.push('/download');
window.location.href = '/download.html';
nav.push({ path: '/download' });
}
};

@ -2,14 +2,13 @@
import { useState } from 'react';
// import { useRouter } from 'next/navigation';
import useNav from '@/hooks/useNav';
import useUA from '@/hooks/useUA';
export default function EnterQueyueBtn() {
// const router = useRouter();
const [opening, setOpening] = useState(false);
const { inWX } = useUA();
const nav = useNav();
const handleEnterQueyue = () => {
if (opening) return;
@ -20,8 +19,7 @@ export default function EnterQueyueBtn() {
if (result) {
window.location.href = `queyue://play/${songId}`; // 打开某手机上的某个app应用
setTimeout(function () {
// router.push('/download');
window.location.href = '/download.html';
nav.push({ path: '/download' });
}, 500);
setOpening(false);
} else {

@ -1,14 +1,13 @@
'use client';
// import { useRouter } from 'next/navigation';
import ImageWithBasePath from '@/components/ImageWithBasePath';
import useNav from '@/hooks/useNav';
export default function InviteBanner() {
// const router = useRouter();
const nav = useNav();
const handleClick = () => {
// router.push('/');
window.location.href = '/index.html';
nav.push({ path: '/index' });
};
return (
<div

@ -1,14 +1,13 @@
'use client';
// import { useRouter } from 'next/navigation';
import ImageWithBasePath from '@/components/ImageWithBasePath';
import useNav from '@/hooks/useNav';
export default function JournalComment({ journalInfo }: { journalInfo: any }) {
// const router = useRouter();
const nav = useNav();
const handleClick = () => {
// router.push('/download');
window.location.href = '/download.html';
nav.push({ path: '/download' });
};
return (
<section className="fixed bottom-0 left-[50%] translate-x-[-50%] z-[999] w-full max-w-screen-sm flex items-center border-t-[0.8px] border-[#00000019] pt-[14px] pb-[35px] px-[18px] bg-white">

@ -1,14 +1,13 @@
'use client';
// import { useRouter } from 'next/navigation';
import ImageWithBasePath from '@/components/ImageWithBasePath';
import useNav from '@/hooks/useNav';
export default function MusicBanner() {
// const router = useRouter();
const nav = useNav();
const handleClick = () => {
// router.push('/');
window.location.href = '/index.html';
nav.push({ path: '/index' });
};
return (
<div

@ -1,26 +1,25 @@
'use client';
import Image from 'next/image';
// import { useRouter } from 'next/navigation';
import ImageWithBasePath from '@/components/ImageWithBasePath';
import styles from './index.module.css';
import { useJournalAudioContext } from '@/context/JournalAudioContext';
import useNav from '@/hooks/useNav';
export default function SongItem(props: { data: ISong }) {
const song = props?.data || {};
const { id, pic, title, artist, album } = song;
// const router = useRouter();
const nav = useNav();
const { curSong, setCurSong, playing, setPlaying } = useJournalAudioContext();
const activeTextColor: string = curSong?.id && id && curSong?.id === id ? 'text-[#C43737ff]' : '';
// 点击歌曲封面跳转到单曲页面
const handleCoverClick = () => {
// router.push(`/music?id=${id}`);
window.location.href = `/music.html?id=${id}`;
nav.push({ path: '/music', query: { id } });
};
// 点击歌曲信息播放歌曲
@ -31,8 +30,7 @@ export default function SongItem(props: { data: ISong }) {
// 点击右侧图标,弹出弹窗(目前先跳转到下载页)
const handleBudsClick = () => {
// router.push('/download');
window.location.href = '/download.html';
nav.push({ path: '/download' });
};
return (

@ -0,0 +1,33 @@
import { useCallback } from 'react';
import { useRouter } from 'next/navigation';
interface INavParams {
path: string;
query?: Record<string, any>;
}
export default function useNav() {
const router = useRouter();
const push = useCallback(
({ path, query }: INavParams) => {
let queryStr = '';
if (query && Object.keys(query).length > 0) {
const queryArr: string[] = [];
Object.entries(query).forEach(([key, val]) => {
queryArr.push(`${key}=${encodeURIComponent(val)}`);
});
queryStr += `?${queryArr.join('&')}`;
}
if (process.env.NODE_ENV === 'production') {
window.location.href = `${path}.html${queryStr}`;
} else {
router.push(`${path}${queryStr}`);
}
},
[router],
);
return { push };
}
Loading…
Cancel
Save