我有嵌套路由,第三级路由失败。这是我的路由结构是的....但问题是,App.js 路由到 -Home -About -Dashboard 然后 Dashboard 有子组件到 -Profile (/dashboard/user) -Account (/dashboard/account) -Wallet (/dashboard/wallet) - 设置 (/dashboard/settings) 然后设置还有其他子组件 - 编辑个人资料 (/dashboard/settings/editprofile) - 编辑密码和 Pin 图 (/dashboard/settings/editpassword) - 编辑帐号 (/仪表板/设置/编辑编号)
前两级路由正在工作,但是当我刷新页面时,最后一个路由失败,尽管当我返回主页并单击链接直到到达最后一个组件时它会呈现,但是一旦我刷新浏览器,它就会中断,当我手动输入时它也不起作用。
这是我的 App.js 路由设置
import {
BrowserRouter as Router,
Switch,
Route,
Redirect,
} from "react-router-dom";
const App = () => {
return (
<div className="App">
{/* setting up the routes */}
<Switch>
<Route path="/" exact component={Home} />
<Route path="/dashboard" component={dashboard} />
<Route path="/login" exact component={Login} />
<Route path="/register" exact component={SignUp} />
<Route path="/about" exact component={AboutServices} />
</Switch>
</Router>
</div>
);
};
我的仪表板.js
import { Route, useRouteMatch, NavLink, Switch } from "react-router-dom";
const App = () => {
let { path, url } = useRouteMatch();
return (
<div className="App">
<nav> Navavigation bar <nav>
{/* setting up the routes */}
<div className="MainBody">
<Switch>
<Route path={`${path}/wallet`} exact component={Wallet} />
<Route path={`${path}/profile`} component={Profile} />
<Route path={`${path}/account`} component={Account} />
<Route path={`${path}/settings`} exact component={Settings} />
</Switch>
</div>
</div>
);
};
设置页面
import {
Switch,
Route,
useRouteMatch,
NavLink,
BrowserRouter,
}
www说
相关分类