reactjs - 我的应用在调用登录时向 URL 添加了一个字符
问题描述
我正在使用前面的反应应用程序,每次我调用登录页面时,它都会在 url 中添加#
应用程序.js
...
import './App.scss'
const loading = () => <div className="animated fadeIn pt-3 text-center">Loading...</div>
const CVThequeIndex = React.lazy(() => import('./views/CVTheque/Index'))
const DepartIndex = React.lazy(() => import('./views/Depart/Index'))
const ServicesIndex = React.lazy(() => import('./views/Services/Index'))
const MonCvIndex = React.lazy(() => import('./views/MonCV/Index'))
const RecrutementIndex = React.lazy(() => import('./views/Recrutement/Index'))
const AccueilIndex = React.lazy(() => import('./views/Accueil/Index'))
const AdminIndex = React.lazy(() => import('./views/Admin/Index'))
const Login = React.lazy(() => import('./views/Pages/Login/Login'))
const PasswordRecover = React.lazy(() => import('./views/Pages/PasswordRecover/PasswordRecover'))
const Error404 = React.lazy(() => import('./views/Pages/Page404/Page404'))
const Error500 = React.lazy(() => import('./views/Pages/Page500/Page500'))
...
return (
<HashRouter>
<React.Suspense fallback={loading()}>
<Switch>
<CollaborateurRoute path="/cvtheque" name="CVTheque" render={props => <CVThequeIndex {...props} />} />
<CollaborateurRoute path="/depart" name="Depart" render={props => <DepartIndex {...props} />} />
<CollaborateurRoute path="/services" name="Services" render={props => <ServicesIndex {...props} />} />
<CollaborateurRoute path="/moncv" name="MonCv" render={props => <MonCvIndex {...props} />} />
<CollaborateurRoute path="/recrutement" name="Recrutement" render={props => <RecrutementIndex {...props} />} />
<CollaborateurRoute path="/accueil" name="Home" render={props => <AccueilIndex {...props} />} />
<AdminRoute path="/admin" name="Admin" render={props => <AdminIndex {...props} />} />
<AuthenticatedRoute path="/deconnexion" name="Logout" render={props => <Login {...props} />} />
<Route path="/connexion" name="Login" render={props => <Login {...props} />} />
<Route exact path="/" name="Login" render={props => <Login {...props} />} />
<Route exact path="" name="Login" render={props => <Login {...props} />} />
...
每次我尝试打开登录页面(或任何其他页面)时,都会在 URL 中添加一个 #。
解决方案
这是因为您使用的是HashRouter
. 我不确定,但我假设你正在使用 React Router 的HashRouter
. BrowserRouter
如果您不想在 URL 中
使用井号,则需要使用 。https://reactrouter.com/web/api/BrowserRouter
推荐阅读
- python - Python Regex 匹配至少一个字母和一个数字的 6 个字符
- python - 如何重构我的 python 以使用 SQL Prepared 语句?
- python - Dash:为什么我的 dash 应用程序在通过命令提示符运行时不工作?
- c++ - 如何找到与 gcc 向量扩展匹配的索引?
- javascript - 为什么输入中的默认值是在键盘上键入任何按钮后设置的
- python - 在 Negamax 中保存有效动作对速度几乎没有影响
- gremlin - Tinkerpop/Gremlin:如何加入多个遍历并在主遍历中使用它们的值?
- javascript - Vuetify 数据表重新渲染事件
- c++ - (.bss+0x0): 'player'的多重定义;
- python - Speedtest-cli 在不同的界面上