fix:处理useRouter ReferenceError: location is not defined
This commit is contained in:
parent
73a402c840
commit
6e42e44fed
|
@ -1,7 +1,7 @@
|
|||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
// Middleware cannot be used with "output: export".
|
||||
// output: 'export',
|
||||
output: 'export',
|
||||
// Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
|
||||
// trailingSlash: true,
|
||||
|
||||
|
@ -9,7 +9,7 @@ const nextConfig = {
|
|||
// skipTrailingSlashRedirect: true,
|
||||
|
||||
// Optional: Change the output directory `out` -> `dist`
|
||||
// distDir: 'dist',
|
||||
distDir: 'docker/out',
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
'use client'
|
||||
import {usePathname, useRouter} from "next/navigation";
|
||||
import { useRouter} from "next/navigation";
|
||||
import dayjs from "dayjs";
|
||||
import {useEffect} from "react";
|
||||
|
||||
export default function Home() {
|
||||
console.log('app.usePathname()', usePathname());
|
||||
const { replace } = useRouter();
|
||||
replace("/task/four")
|
||||
dayjs.locale('zh-cn')
|
||||
return (
|
||||
<main className="flex min-h-screen flex-col p-6">
|
||||
</main>
|
||||
);
|
||||
const {replace} = useRouter();
|
||||
useEffect(()=>{
|
||||
replace("/task/four")
|
||||
},[])
|
||||
dayjs.locale('zh-cn')
|
||||
return (
|
||||
<main className="flex min-h-screen flex-col p-6">
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
export const dynamic = 'force-dynamic' // defaults to auto
|
||||
|
||||
export async function GET(request: Request) {
|
||||
return new Response('Hello, Next.js!', {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
import { NextResponse } from 'next/server'
|
||||
import type { NextRequest } from 'next/server'
|
||||
// export const config = {
|
||||
// matcher: ['/task/four', '/task/project','/search/task_message_tree'],
|
||||
// }
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
// Clone the request headers and set a new header `x-hello-from-middleware1`
|
||||
// const requestHeaders = new Headers(request.headers)
|
||||
// requestHeaders.set('x-hello-from-middleware1', 'hello')
|
||||
console.log('middleware:',request)
|
||||
// You can also set request headers in NextResponse.rewrite
|
||||
const response = NextResponse.next({
|
||||
request: {
|
||||
// New request headers
|
||||
// headers: requestHeaders,
|
||||
},
|
||||
})
|
||||
|
||||
// Set a new response header `x-hello-from-middleware2`
|
||||
response.headers.set('x-hello-from-middleware2', 'hello')
|
||||
return response
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
import { GlobeAltIcon } from '@heroicons/react/24/outline';
|
||||
|
||||
export default function AcmeLogo() {
|
||||
return (
|
||||
<div
|
||||
className={`flex flex-row items-center leading-none text-white`}
|
||||
>
|
||||
{/*<GlobeAltIcon className="h-12 w-12 rotate-[15deg]" />*/}
|
||||
<p className="text-[44px]">Acme</p>
|
||||
</div>
|
||||
);
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
import {
|
||||
UserGroupIcon,
|
||||
HomeIcon,
|
||||
DocumentDuplicateIcon,
|
||||
} from '@heroicons/react/24/outline';
|
||||
|
||||
// Map of links to display in the side navigation.
|
||||
// Depending on the size of the application, this would be stored in a database.
|
||||
const links = [
|
||||
{ name: 'Home', href: '/dashboard', icon: HomeIcon },
|
||||
{
|
||||
name: 'Invoices',
|
||||
href: '/dashboard/invoices',
|
||||
icon: DocumentDuplicateIcon,
|
||||
},
|
||||
{ name: 'Customers', href: '/dashboard/customers', icon: UserGroupIcon },
|
||||
];
|
||||
|
||||
export default function NavLinks() {
|
||||
return (
|
||||
<>
|
||||
{links.map((link) => {
|
||||
const LinkIcon = link.icon;
|
||||
return (
|
||||
<a
|
||||
key={link.name}
|
||||
href={link.href}
|
||||
className="flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3"
|
||||
>
|
||||
{/*<LinkIcon className="w-6" />*/}
|
||||
<p className="hidden md:block">{link.name}</p>
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
import Link from 'next/link';
|
||||
import NavLinks from '@/ui/dashboard/nav-links';
|
||||
import AcmeLogo from '@/ui/acme-logo';
|
||||
import { PowerIcon } from '@heroicons/react/24/outline';
|
||||
|
||||
export default function SideNav() {
|
||||
return (
|
||||
<div className="flex h-full flex-col px-3 py-4 md:px-2">
|
||||
<Link
|
||||
className="mb-2 flex h-20 items-end justify-start rounded-md bg-blue-600 p-4 md:h-40"
|
||||
href="/public"
|
||||
>
|
||||
<div className="w-32 text-white md:w-40">
|
||||
<AcmeLogo />
|
||||
</div>
|
||||
</Link>
|
||||
<div className="flex grow flex-row justify-between space-x-2 md:flex-col md:space-x-0 md:space-y-2">
|
||||
<NavLinks />
|
||||
<div className="hidden h-auto w-full grow rounded-md bg-gray-50 md:block"></div>
|
||||
<form>
|
||||
<button className="flex h-[48px] w-full grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3">
|
||||
<PowerIcon className="w-6" />
|
||||
<div className="hidden md:block">Sign Out</div>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
// import { Inter,Lusitana } from 'next/font/google';
|
||||
//
|
||||
// export const inter = Inter({ subsets: ['latin'] });
|
||||
// export const lusitana = Lusitana({
|
||||
// weight: ['400', '700'],
|
||||
// subsets: ['latin'],
|
||||
// });
|
|
@ -86,7 +86,7 @@ const CalShow: React.FC = () => {
|
|||
return () => {
|
||||
clearClickTimeout()
|
||||
}
|
||||
}, [useContext(LocalContext)]);
|
||||
}, [useContext(LocalContext),range]);
|
||||
const message = {
|
||||
week: '周',
|
||||
work_week: '工作周',
|
||||
|
|
|
@ -100,10 +100,10 @@ export const DetailModelForm: React.FC<DetailModelFormProps> = (props) => {
|
|||
props.reloadData?.();
|
||||
},
|
||||
}}
|
||||
submitter={props.itemId!==undefined?{
|
||||
submitter={props.itemId!==undefined&&props.itemId!=-1?{
|
||||
render: (prop, defaultDoms) => {
|
||||
return [
|
||||
<Button
|
||||
editFormDisable?<Button
|
||||
key="edit"
|
||||
onClick={() => {
|
||||
// props.submit();
|
||||
|
@ -111,8 +111,9 @@ export const DetailModelForm: React.FC<DetailModelFormProps> = (props) => {
|
|||
}}
|
||||
>
|
||||
编辑
|
||||
</Button>,
|
||||
</Button>:undefined,
|
||||
<Popconfirm
|
||||
key ='delete'
|
||||
title="删除任务"
|
||||
description="确认要删除任务?"
|
||||
icon={<QuestionCircleOutlined style={{color: 'red'}}/>}
|
||||
|
|
|
@ -132,7 +132,7 @@ const TreeTablePro: React.FC = () => {
|
|||
}
|
||||
];
|
||||
let toolBarRenderList = [
|
||||
<DetailModelForm key={1} operationId={OPERATION_BUTTON_TYPE.ADD} description='添加主线任务' reloadData={()=>{
|
||||
<DetailModelForm open={false} haveButton={true} key={1} operationId={OPERATION_BUTTON_TYPE.ADD} description='添加主线任务' reloadData={()=>{
|
||||
actionRef.current?.reload( false);
|
||||
}}/>,
|
||||
<Switch key={2} checkedChildren="树" unCheckedChildren="列表" checked={switchChecked}
|
||||
|
|
Loading…
Reference in New Issue