|
1 |
| ---- |
2 |
| -title: Catch-all routes |
3 |
| ---- |
4 |
| - |
5 |
| -Catch-all routes are used to match any URL that does not match any other route in the application. |
6 |
| -This is useful for displaying a 404 page or redirecting to a specific route when a user enters an invalid URL. |
7 |
| - |
8 |
| -To create a catch-all route, place a route with a asteriks `*` as the path at the end of the route list. |
9 |
| -Optionally, you can name the parameter to access the unmatched part of the URL. |
10 |
| - |
11 |
| -```jsx |
12 |
| -import { Router, Route } from "@solidjs/router"; |
13 |
| - |
14 |
| -import Home from "./Home"; |
15 |
| -import About from "./About"; |
16 |
| -import NotFound from "./NotFound"; |
17 |
| - |
18 |
| -const App = () => ( |
19 |
| - <Router> |
20 |
| - <Route path="/home" element={<Home />} /> |
21 |
| - <Route path="/about" element={<About />} /> |
22 |
| - <Route path="*404" element={<NotFound />} /> |
23 |
| - </Router> |
24 |
| -); |
25 |
| -``` |
26 |
| - |
| 1 | +--- |
| 2 | +title: Catch-all routes |
| 3 | +--- |
| 4 | + |
| 5 | +Catch-all routes are used to match any URL that does not match any other route in the application. |
| 6 | +This is useful for displaying a 404 page or redirecting to a specific route when a user enters an invalid URL. |
| 7 | + |
| 8 | +To create a catch-all route, place a route with a asteriks `*` as the path at the end of the route list. |
| 9 | +Optionally, you can name the parameter to access the unmatched part of the URL. |
| 10 | + |
| 11 | +```jsx |
| 12 | +import { Router, Route } from "@solidjs/router"; |
| 13 | + |
| 14 | +import Home from "./Home"; |
| 15 | +import About from "./About"; |
| 16 | +import NotFound from "./NotFound"; |
| 17 | + |
| 18 | +const App = () => ( |
| 19 | + <Router> |
| 20 | + <Route path="/home" component={Home} /> |
| 21 | + <Route path="/about" component={About} /> |
| 22 | + <Route path="*404" component={NotFound} /> |
| 23 | + </Router> |
| 24 | +); |
| 25 | +``` |
| 26 | + |
27 | 27 | Now, if a user navigates to a URL that does not match `/home` or `/about`, the `NotFound` component will be rendered.
|
0 commit comments