import React from 'react';
import { BrowserRouter as Router, Route, Switch, Redirect } from 'react-router-dom';
import Footer from './components/Footer';
import NavMenu from './components/NavMenu';
import ScrollToTop from './components/ScrollToTop';
import About from './pages/About';
import Contact from './pages/Contact';
import Home from './pages/Home';
import Projects from './pages/Projects';
import Gallery from './pages/Gallery';
export default function App() {
return (
<>
<Router>
<NavMenu />
<ScrollToTop />
<Switch>
<Route path="/about">
<About />
</Route>
<Route path="/contact">
<Contact />
</Route>
<Route path="/projects">
<Projects />
</Route>
<Route path="/gallery/">
<Redirect to="/projects" />
<Gallery />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
<Footer />
</Router>
</>
);
}
问题是,我希望它重定向(example.com/gallery)到(example.com/projects),但让我使用类似于(example.com/gallery/photo1)的内容,而不重定向到(example.com/projects)
2条答案
按热度按时间jljoyd4f1#
呈现两个单独的路径,一个用于从
"/gallery"
重定向到"/projects"
,另一个用于 a 特定的画廊。示例:
yvgpqqbh2#
您可以使用
exact
属性指定精确路由,这意味着子路由将不匹配。