Concepts

Catch-all 路由

编辑此页面

Catch-all 路由用于匹配不符合应用程序中任何其他路由的 URL。这对于显示 404 页面或在用户输入无效 UR L时重定向到特定路由非常有用。

要创建一个 catch-all 路由,请在路由列表末尾放置一个带星号 * 的路径。您可以命名这个参数以访问 URL 未匹配的部分。

import { Router, Route } from "@solidjs/router";
import Home from "./Home";
import About from "./About";
import NotFound from "./NotFound";
const App = () => (
<Router>
<Route path="/home" component={Home} />
<Route path="/about" component={About} />
<Route path="*404" component={NotFound} />
</Router>
);

现在,如果用户导航到与 /home/about 不匹配的 URL,将会渲染 NotFound 组件。

报告此页面问题