react-router-dom v6 版本中使用 useRoutes 進(jìn)行統(tǒng)一路由管理,并導(dǎo)出使用释涛。
import * as React from "react";
import { useRoutes } from "react-router-dom";
function App() {
let element = useRoutes([
{
path: "/",
element: <Dashboard />,
children: [
{
path: "messages",
element: <DashboardMessages />,
},
{ path: "tasks", element: <DashboardTasks /> },
],
},
{ path: "team", element: <AboutPage /> },
]);
return element;
}
在 Vite 中使用 useRoutes 會(huì)報(bào) Uncaught SyntaxError: Unexpected token '<' 的錯(cuò)
配置內(nèi)容
報(bào)錯(cuò)結(jié)果
但是使用 create-react-app 創(chuàng)建的項(xiàng)目就不會(huì)有這個(gè)問(wèn)題
最后在試錯(cuò) 度娘等操作中發(fā)現(xiàn)將 routes 中的 index.js 改為 index.jsx 就可以了 ??