# Hash-based routes

> Count `/#/settings` style routes as separate pages in single-page apps that route with the URL hash.

Most single-page apps change pages with the History API (`/pricing`, `/settings`), which the script follows on its own. Some apps route with the hash instead: `https://example.com/#/pricing`. By default the script ignores the part after `#`, because on ordinary sites it only points to a heading on the same page, so every hash route would count as one page, `/`.

Add `data-hash="true"` to count each hash route as its own page:

```html
<script
  defer
  data-website-id="ws_your_tracking_id"
  data-hash="true"
  src="https://reveata.com/js/script.js"
></script>
```

Tag managers and builders that can't set attributes can use the script address instead: `https://reveata.com/js/script.js?website-id=ws_your_tracking_id&hash=true`. With the npm packages, pass `hash: true`.

## What changes

- **A pageview on every hash change.** The script listens for `hashchange` as well as History API changes. Changing only the query string is not a new page.
- **The route becomes part of the path.** `https://example.com/app/#/settings/billing` is stored as the page `/app/#/settings/billing`. Hashbang routes (`#!/settings`) work the same way. A hash that doesn't start with `/` or `!/` (a plain `#pricing` anchor) is not added to the path.
- **Query strings inside the route are filtered.** `#/signup?utm_source=newsletter&token=abc` keeps only the campaign parameters (`utm_*`, `ref`, `via`, `source` and ad click ids), exactly like a normal query string. Other values, such as tokens, are never stored.
- **Campaigns are read from both places.** UTM tags and `?ref=` work in the real query string (`/?utm_source=x#/home`) and in the route's own query (`/#/home?utm_source=x`).

## Which routers need it

| Router | Setting that uses the hash | Needs `data-hash` |
| --- | --- | --- |
| Vue Router | `createWebHashHistory()` | Yes |
| React Router | `createHashRouter` or `<HashRouter>` | Yes |
| Angular | `withHashLocation()` or `useHash: true` | Yes |
| Any router in History mode | `createWebHistory()`, `createBrowserRouter`, Angular's default | No |

Install guides: [Vue](https://reveata.com/docs/vue), [React Router](https://reveata.com/docs/react-router), [Angular](https://reveata.com/docs/angular).

## Goals and filters

Page filters, funnels and page-visit goals match the stored path, so include the hash: a goal for `/#/checkout/done`, or a filter `Page starts with /#/settings`. Wildcards work as usual, for example `/#/docs/*`.

## Check it works

Open your app, move between a few routes, and watch the **Realtime** view: each route should appear as its own page. Add `data-debug="true"` to see each pageview the script sends in the browser console.
