Skip to content

Instantly share code, notes, and snippets.

@bigujun
bigujun / gist:5bdb40c3fcedd5ca3e8e3c4e3dcc8541
Created May 3, 2022 20:00
Vite + React + React rotuer dom, route pages from /pages
import { Fragment, lazy, Suspense } from 'react'
import { Routes, Route } from 'react-router-dom'
const PRESERVED = import.meta.globEager('/src/pages/(_app|404).tsx')
const ROUTES = import.meta.glob('/src/pages/**/[a-z[]*.tsx')
// const ROUTES = import.meta.globEager('/src/pages/**/[a-z[]*.tsx')
const preserved = Object.keys(PRESERVED).reduce((preserved, file) => {
const key = file.replace(/\/src\/pages\/|\.tsx$/g, '')