"react-router-dom"
与<Switch>
和<Route>
。-在我的网站上,我有菜单和子菜单。-ex ::菜单(括号中带有路径)
1) Home ('/home') , 2) Profile ('/profile') , 3) Admin ('/admin')
ex ::子菜单::只有“管理”选项卡具有子菜单
a) setting ('/admin/setting') and b) History ('/admin/history')
App.js
constructor(props) {
history = createBrowserHistory();
if (window.performance) {
localStorage.setItem("currentpath",window.location.pathname);
this.login();
}
}
login = () =>{
//ajax call
//after ajax response
let currentpath = localStorage.getItem("currentpath");
if(currentpath)
this.history.push(currentpath );
else
this.history.push('/home');
}
render() {
return (
<React.Fragment>
<Router history={this.history}>
<div>
<Switch>
<Route exact path="/" render={() => <Login/>} />
<Route exact path="/home" render={() =><HomepageLayout/>} />
<Route path="/admin" render={() => <AdminPageLayout/>} />
<Route path="/profile" render={() => <ProfilePageLayout />} />
</Switch>
</div>
</Router>
</React.Fragment>
)
}
现在的问题是,“local server
刷新”对于所有路径都工作正常。但是当当前页面为和时,live server
刷新工作正常。但是对于或子菜单选项卡刷新不起作用。Home
Profile
Admin->setting
Admin->history
我在控制台中遇到的这些错误
GEThttp://www.websoft.com/admin/setting [HTTP/1.1 304 Not Modified 322ms]
GEThttp://www.websoft.com/admin/static/css/1.3ac8ff05.chunk.css [HTTP/1.1 200 OK 341ms]
GEThttp://www.websoft.com/admin/static/js/1.ef821ff9.chunk.js [HTTP/1.1 304 Not Modified 324ms]
GEThttp://www.websoft.com/admin/static/js/main.f0eaa457.chunk.js [HTTP/1.1 304 Not Modified 329ms]
GEThttp://www.websoft.com/admin/static/css/main.83e337cf.chunk.css
The stylesheet http://www.websoft.com/admin/static/css/1.3ac8ff05.chunk.css was not loaded because its MIME type, “text/html”, is not “text/css”.
The script from “http://www.websoft.com/admin/static/js/1.ef821ff9.chunk.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type
admin
当我刷新子菜单时,它添加到块文件的路径中。
package.json
参数“ homepage ”,这对于制造建筑很有用。"homepage": "."
我package.josn
来"homepage": "/"
。package.json
解决问题的最新方法。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句