I know maybe this topic is duplicate, but I ask because I failed to try the answer about my problem with the answer I found with the similar topic.
(我知道这个主题可能是重复的,但是我问是因为我没有用关于类似主题的答案来尝试有关问题的答案。)
as the title said I want to make my route like [some-web-link].com/order , but my problem is the page works fine in localhost or when I first hit my [some-web-link].com/ , but when I directly type like [some-web-link].com/order it failed and return 404 Not Found .
(如标题所述,我想使路由类似[some-web-link] .com / order ,但是我的问题是该页面在localhost或当我第一次点击[some-web-link] .com /时工作正常 ,但是当我直接键入[some-web-link] .com / order时,它失败并返回404 Not Found 。)
I find it maybe because of my router like some the answer in here:(我发现这可能是因为我的路由器喜欢这里的答案:)
how-to-fix-react-page-not-working-after-refresh
(如何修复刷新后无法工作的页面)
react-router-urls-dont-work-when-refreshing-or-writing-manually
(手动刷新或书写时反应路由器网址不工作)
react-router-no-not-found-route
(反应路由器找不到路由)
but still no luck.
(但仍然没有运气。)
this is my app.js:
(这是我的app.js:)
import React from 'react';
import { Router, Switch, Route, Redirect, BrowserRouter } from 'react-router-dom';
import { history } from './Helpers';
import { PrivateRoute } from './Components/PrivateRoute';
// Components
import './App.css';
import Homepage from './Components/homepage/homepage';
import Orderpage from './Components/orderpage/orderpage';
import Cart from './Components/cart/cart';
import { Login } from './Components/Login/Login';
import { Signup } from './Components/Signup/Signup';
import { Dashboard } from './Components/Dashboard/Dashboard';
import { Order } from './Components/Order/Order';
import { Product } from './Components/product/product';
import { ProductDetail } from './Components/product/productdetail/productdetail';
function App() {
return (
<BrowserRouter>
<div>
<Router history={history}>
<Switch>
<Route exact path="/" component={Homepage} />
<Route exact path="/order" component={Orderpage} />
<Route exact path="/cart" component={Cart} />
<Route exact path='/login' component={Login} />
<Route exact path='/sign-up' component={Signup} />
{/* <Route exact path='/' render={() => (<Redirect to="/dashboard" />)} /> */}
<PrivateRoute exact path='/dashboard' component={Dashboard}/>
<PrivateRoute exact path='/user-order' component={Order}/>
<PrivateRoute exact path='/products' component={Product}/>
<PrivateRoute exact path='/products/product-detail/:id' component={ProductDetail}/>
<Route path='*' component={Homepage} />
</Switch>
</Router>
</div>
</BrowserRouter>
);
}
export default App;
you can see that i tried to use redirect or catch-all but still failed.
(您可以看到我尝试使用重定向或全部使用,但仍然失败。)
Can someone help me tell where I did wrong?(有人可以帮我说我做错了什么吗?)
ask by Rakis Friski translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…