Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 995 Bytes

README.md

File metadata and controls

55 lines (42 loc) · 995 Bytes

umi-plugin-ssr-routes

A umi plugin that addresses the issue of static route configurations in UmiJS. This plugin aims to render route and menu information from an API, instead of displaying the static routes.

Install

pnpm i umi-plugin-ssr-routes
yarn add umi-plugin-ssr-routes
npm install umi-plugin-ssr-routes

Usage

Configure in .umirc.ts,

export default {
  plugins: [
    ['umi-plugin-ssr-routes'],
  ],
  ssrRoutes: {}
}

Configure in app.ts\tsx\js,

export async function getServerSideRoutes(): Promise<ServerRouteResponse[]> {
  return await getUserRoutes().then((res) => {
    if (res.data) {
      return res.data;
    } else {
      return [];
    }
  });
}

/** GET /api/getUserRoutes */
export async function getUserRoutes(options?: { [key: string]: any }) {
  return request<{
    data: ServerRouteResponse[];
  }>('/api/GetUserRoutes', {
    method: 'GET',
    prefix: undefined,
    ...(options || {}),
  });
}

LICENSE

MIT