【发布时间】:2021-11-14 16:08:36
【问题描述】:
在我的情况下,如果页面更改,加载屏幕将显示。
例如:
http://localhost:3000/ ----> http://localhost:3000/fr
页面转换时会显示加载屏幕
我想隐藏其他组件。我该怎么做?
import "tailwindcss/tailwind.css";
import "../styles/main.css";
import Router from "next/router";
import { useState } from "react";
import Loader from "../components/Loader/Loader";
function MyApp({ Component, pageProps }) {
const [loading, setloading] = useState(false);
Router.events.on("routeChangeStart", (url) => {
// inspect the router changing start
console.log("Router change...");
setloading(true);
});
Router.events.on("routeChangeComplete", (url) => {
// inspect the router changing complete
console.log("Router change completed");
setloading(false);
});
return (
<>
<Loader loadingbool={loading}/>
<Component {...pageProps}/>
</>
);
}
export default MyApp;
【问题讨论】:
标签: reactjs next.js tailwind-css