react路由管理

import {useRoutes} from "react-router-dom";
import Layout from '@/layout'
import Home from '@/pages/首页'
import Details from '@/pages/详情'


const router = [
  {
    path: '/',
    element: ()
  },
  {
    path: '/index',
    element: (),
    children:[
      // 首页
      {
        path: '',
        element: ()
      },
    
      {
        path: 'details',
        element: (
) } ] } ] const RouterView = () => { return useRoutes(router) } export default RouterView
import {useLocation,useNavigate} from 'react-router-dom'
// 获取
const location = useLocation()
location.pathname 

// 跳转
  const navigate = useNavigate();
  navigate('/')

你可能感兴趣的:(前端,react.js,javascript,前端)