Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何配置 React-Router 实现路由切换 #553

Open
lgwebdream opened this issue Jul 6, 2020 · 3 comments
Open

如何配置 React-Router 实现路由切换 #553

lgwebdream opened this issue Jul 6, 2020 · 3 comments
Labels
React teach_tag 滴滴 company 阿里 company

Comments

@lgwebdream
Copy link
Owner

No description provided.

@lgwebdream lgwebdream added React teach_tag 滴滴 company 阿里 company labels Jul 6, 2020
@lgwebdream
Copy link
Owner Author

扫描下方二维码,获取答案以及详细解析,同时可解锁800+道前端面试题。

@gujiwuqing
Copy link

import { Switch,BrowserRouter as Router ,Route} from 'react-router-dom'

<Router>
<NavLink to='/'>首页</NavLink>
<NavLink to='/test'>测试</NavLink>
<Switch>
<Route path='/' component={Home}/>
<Route path='/test' component={Test}/>
</Switch>
</Router>

@LoveWei0
Copy link

LoveWei0 commented Jun 9, 2023

配置react Router 实现路由切换

import { useRoutes } from "react-router-dom"
import { Navigate } from 'react-router-dom'
// 引入组件
import Login from "../pages/Login";
import Center from "../pages/Center";
import Music from '../pages/Center/component/Music'
import Game from '../pages/Center/component/Game'
import News from '../pages/Center/component/News'
import Count from '@/pages/Count'
import TodoList from '@/pages/TodoList/index'
import SubmitBottom from '@/components/SubmitBottom'
//路由表
export const routes = [
  {
    path: "/login",
    element: <Login />,
  },
  {
    path: "/count",
    element: <Count />
  },
  {
    path: '/todo',
    element: <TodoList />
  },
  {
    path: '/submitBottom',
    element: <SubmitBottom />
  },
  {
    path: "/center",
    element: <Center />,
    children: [
      {
        path: "/center/music",
        element: <Music />
      },
      {
        path: "/center/news",
        element: <News />
      },
      {
        path: "/center/game/:id?/:type",
        element: <Game />
      }
    ]
  },
  {
    path: "/",
    element: <Navigate to="/center" />
  }
];
const Router = useRoutes(routes)
export default Router

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
React teach_tag 滴滴 company 阿里 company
Projects
None yet
Development

No branches or pull requests

3 participants