feat(rewrite): support micro frontend
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export const BASE_LABEL_API =
|
||||
process.env.NEXT_PUBLIC_ENV === "production"
|
||||
? "https://label.cowarobot.com"
|
||||
: "http://172.16.112.8:9110"
|
||||
: "https://label.softtest.cowarobot.com"
|
||||
|
||||
@@ -86,7 +86,8 @@ export default function AppLayout({
|
||||
e.preventDefault()
|
||||
if (activeHeaderMenu?.url === item.url) return
|
||||
let toPathname = menuDefaultRouter[`/${item.url}`] || `/${item.url}`
|
||||
router.push(toPathname)
|
||||
window.location.href = toPathname
|
||||
// router.replace(toPathname)
|
||||
}}>
|
||||
<ClientIcon icon={item.icon} style={{ width: "1rem", height: "1rem" }} />
|
||||
{item.title}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
import { useAppLayoutStore } from "@/components/layout/store"
|
||||
// import { useLoginStore } from "../login/store"
|
||||
import { MenuItem } from "./common"
|
||||
import { usePathname, useSearchParams } from "next/navigation"
|
||||
import { useEffect, useMemo } from "react"
|
||||
import { MenuItem } from "./common"
|
||||
interface ComponentProps {
|
||||
menu: MenuItem[] | undefined
|
||||
}
|
||||
@@ -45,7 +45,9 @@ export function PathnameRecorder({ menu }: ComponentProps) {
|
||||
`/${sideNavMenu?.url}` !== pathname &&
|
||||
updateMenuDefaultRouter(
|
||||
`/${sideNavMenu?.url}`,
|
||||
queryString ? `${pathname}?${queryString}` : pathname
|
||||
queryString
|
||||
? `${process.env.NEXT_PUBLIC_BASE_PATH}${pathname}?${queryString}`
|
||||
: `${process.env.NEXT_PUBLIC_BASE_PATH}${pathname}`
|
||||
)
|
||||
}, [queryString, pathname, sideNavMenu?.url, updateMenuDefaultRouter])
|
||||
return <></>
|
||||
|
||||
@@ -96,6 +96,16 @@ export const componentList: MenuItem[] = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "图片标注",
|
||||
url: "image",
|
||||
icon: "SystemIcon",
|
||||
},
|
||||
{
|
||||
title: "视频标注",
|
||||
url: "video",
|
||||
icon: "SystemIcon",
|
||||
},
|
||||
]
|
||||
|
||||
export const showList: MenuItem[] = []
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Login } from "./types"
|
||||
const BASE_PATH =
|
||||
process.env.NEXT_PUBLIC_ENV === "production"
|
||||
? "https://basis.soft.cowarobot.com"
|
||||
: "https://basis.softtest.cowarobot.cn"
|
||||
: "https://basis.softtest.cowarobot.com"
|
||||
|
||||
// 获取验证码
|
||||
export const getVerifyCode = (params: { phone: string }) => {
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
import type { NextConfig } from "next"
|
||||
|
||||
const subList: { source: string; url: string }[] = [
|
||||
{
|
||||
source: "/image",
|
||||
url: "http://localhost:5532",
|
||||
},
|
||||
{
|
||||
source: "/video",
|
||||
url: "http://localhost:5533",
|
||||
},
|
||||
]
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
basePath: process.env.NEXT_PUBLIC_BASE_PATH,
|
||||
@@ -7,6 +18,22 @@ const nextConfig: NextConfig = {
|
||||
| "standalone"
|
||||
| "export"
|
||||
| undefined,
|
||||
async rewrites() {
|
||||
// 应用代理baseAppProxy
|
||||
const repoProxy = subList.map(({ source, url }) => {
|
||||
return {
|
||||
source,
|
||||
destination: `${url}${source}`,
|
||||
}
|
||||
})
|
||||
const repoPathProxy = subList.map(({ source, url }) => {
|
||||
return {
|
||||
source: `${source}/:path*`,
|
||||
destination: `${url}${source}/:path*`,
|
||||
}
|
||||
})
|
||||
return [...repoProxy, ...repoPathProxy]
|
||||
},
|
||||
}
|
||||
|
||||
export default nextConfig
|
||||
|
||||
Reference in New Issue
Block a user