Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

javascript - 如何在React中使用hookrouter包创建私有和受保护的路由?(how to create private and protected routes using hookrouter package in React?)

I'm trying to implement private and public routes using hookrouter package in Reactjs.(The app is based on react-hooks.)The snippet of my code is as follows-

(我正在尝试使用Reactjs中的hookrouter包实现私有和公共路由(该应用程序基于react-hooks)。我的代码片段如下-)

in routes.js

(在routes.js中)

export const publicRoutes = {
  "/": () => <Login />,
  "/Signup": () => <Signup />,
}

export const privateRoutes = {
  "/Dashboard": () => <Dashboard />,
}

in App.js

(在App.js中)

import { useRoutes, navigate} from "hookrouter";

const publicRoutesApp = useRoutes(publicRoutes);
const privateRoutesApp = useRoutes(privateRoutes);

{!isLoggedIn() ? publicRoutesApp : privateRoutesApp}
  ask by ravi kumar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...