初始化模版工程
This commit is contained in:
20
app/RouteChange.tsx
Normal file
20
app/RouteChange.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
// components/RouterListener.tsx
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { usePathname, useSearchParams } from "next/navigation";
|
||||
|
||||
export default function RouteChange() {
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
useEffect(() => {
|
||||
const url = searchParams.toString()
|
||||
? `${pathname}?${searchParams.toString()}`
|
||||
: pathname;
|
||||
|
||||
window.parent.postMessage({ type: "ROUTE_CHANGE", path: url }, "*");
|
||||
}, [pathname, searchParams]);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user