Skip to content

Commit

Permalink
Rewrite first two FAQ sections.
Browse files Browse the repository at this point in the history
  • Loading branch information
molefrog committed Jan 31, 2024
1 parent 1455d06 commit d0bea5a
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions README.md
Expand Up @@ -169,9 +169,9 @@ Import from `wouter` module.

### `useRoute`: route patterns and parameters

Checks if current location matches the pattern provided and returns an object with parameters. This is powered by a wounderful [`regexparam`](https://github.com/lukeed/regexparam) library, so all its pattern syntax is fully supported.
Checks if the current location matches the pattern provided and returns an object with parameters. This is powered by a wonderful [`regexparam`](https://github.com/lukeed/regexparam) library, so all its pattern syntax is fully supported.

You can use `useRoute` to perform manual routing or implement custom logic such as route transitions etc.
You can use `useRoute` to perform manual routing or implement custom logic, such as route transitions, etc.

```js
import { useRoute } from "wouter";
Expand All @@ -188,6 +188,26 @@ const Users = () => {
};
```

A quick cheatsheet of what types of segments are supported:

```js
useRoute("/app/:page");
useRoute("/app/:page/:section");

// optional parameter, matches "/en/home" and "/home"
useRoute("/:locale?/home");

// suffixes
useRoute("/movies/:title.(mp4|mov)");

// wildcards, matches "/app", "/app-1", "/app/home"
useRoute("/app*");

// optional wildcards, matches "/orders", "/orders/"
// and "/orders/completed/list"
useRoute("/orders/*?");
```

### `useLocation` hook: working with the history

The low-level navigation in wouter is powered by the `useLocation` hook, which is basically a
Expand Down Expand Up @@ -550,9 +570,17 @@ const App = () => (
);
```

**Note:** _the base path feature is only supported by the default browser History API location hook
(the one exported from `"wouter/use-location"`). If you're implementing your own location hook,
you'll need to add base path support yourself._
Calling `useLocation()` within a route in an app with base path will return a path scoped to the base. Meaning that when base is `"/app"` and pathname is `"/app/users"` the returned string is `"/users"`. Accordingly, calling `navigate` will automatically append the base to the path argument for you.

When you have multiple nested routers, base paths are inherited and stack up.

```js
<Router base="/app">
<Router base="/cms">
<Route path="/users">Path is /app/cms/users!</Route>
</Router>
</Router>
```

### How do I make a default route?

Expand Down

0 comments on commit d0bea5a

Please sign in to comment.