You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/develop/routing.md
+27-30Lines changed: 27 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,25 +6,10 @@ id: routing
6
6
import Tabs from '@theme/Tabs';
7
7
import TabItem from '@theme/TabItem';
8
8
9
+
## Routing on Swarm
9
10
10
-
Swarm's serverless architecture obviously doesn't support server-side routing, but there are several alternative approaches which work well for different circumstances: hash-based client-side routing, manifest-based clean URLs, or directory-style routing (also requires manifest manipulation). Each comes with its own trade-offs in simplicity, flexibility, and URL aesthetics. Here’s the quick overview before we dive into the details.
11
+
Swarm does not behave like a traditional web server — there is **no server-side routing**, and every route must correspond to a real file inside the site [manifest](/docs/develop/manifests).
|**Hash Routing**| Routes live after `/#/` and are handled entirely in the browser | Easiest to implement, zero manifest edits, highly reliable | URLs use `/#/`, not the cleanest visually |
15
-
|**Manifest Clean URLs**| Add aliases or rewrite paths directly in the manifest | Real clean URLs like `/about`, flexible control | Requires manual manifest manipulation |
16
-
|**Directory-Style Routing**| Use folder structures with `index.html`| Clean URLs with familiar static-site patterns | More structure in your build, still needs manifest awareness |
17
-
18
-
Now let’s look at each method, starting with the simplest and most Swarm-friendly option: hash-based client-side routing.
19
-
20
-
21
-
## Client-Side Hash Routing
22
-
23
-
This section explains how to add hash based client side routing to your Swarm hosted site so that you can have clean URLs for each page of your website. See the [routing project in the examples repo](https://github.com/ethersphere/examples/tree/main/routing) for a full working example implementation.
24
-
25
-
### Why Hash Based Client Side Routing?
26
-
27
-
Swarm does not behave like a traditional web server — there is **no server-side routing**, and every route must correspond to a real file inside the site manifest.
28
13
If you try to use typical "clean URLs" like:
29
14
30
15
```bash
@@ -41,12 +26,20 @@ contact
41
26
dashboard/settings
42
27
```
43
28
44
-
...which obviously don’t exist unless you manually manipulate the manifest.
45
-
This is theoretically possible, but is tricky and complex to do manually, and there is currently not (yet) any tooling to make it easier.
29
+
...which obviously don’t exist.
46
30
47
-
### How to Add Routing
31
+
There are two main strategies for addressing routing:
48
32
49
-
If you want multiple pages on a Swarm-hosted website, you should use a client-side router. Swarm has no server backend running code and so can’t rewrite paths, so we use **React Router’s `HashRouter`**, which keeps all routing inside the browser.
33
+
***Hash-Based Client-Side Routing**
34
+
***Manifest-Based Routing with Aliases or Index Files**
35
+
36
+
Now let’s look at each method:
37
+
38
+
## Client-Side Hash Routing
39
+
40
+
This section explains how to add hash based client side routing to your Swarm hosted site so that you can have clean URLs for each page of your website. See the [routing project in the examples repo](https://github.com/ethersphere/examples/tree/main/routing) for a full working example implementation.
41
+
42
+
Swarm has no server backend running code and so can’t rewrite paths, so we can use **React Router’s `HashRouter`**, which keeps all routing inside the browser.
50
43
51
44
Below is the simplest way to set this up using **create-swarm-app** and then adding your own pages.
52
45
@@ -303,11 +296,15 @@ You now have:
303
296
* A React 404 for invalid hash paths
304
297
* Stable, versioned deployments using feed manifests
305
298
306
-
## Add transition here
299
+
## Manifest Based Routing
300
+
301
+
The second routing method involves directly manipulating the manifest so that routes resolve properly to the intended content. There are two primary approaches to manifest based routing:
302
+
303
+
* Alias based routing with arbitrary file names
304
+
* Directory based with index files
307
305
308
-
## Website Routing
309
306
310
-
####1. Upload the Site
307
+
### 1. Upload the Site
311
308
312
309
Start by uploading the site:
313
310
@@ -325,11 +322,11 @@ Without manifest edits, routes only work via exact file paths like:
To "delete" a page you would need to remove all entries for it from the manifest to remove it entirely:
361
358
@@ -399,7 +396,7 @@ Once you understand manifest-based routing, you can dynamically:
399
396
* Add new paths (e.g. blog posts, product pages)
400
397
* Create custom routes
401
398
* Redirect old paths
402
-
*
399
+
*Remove unwanted paths
403
400
404
-
Next, learn how manifest manipulation plays a key role in enabling the[dynamic content](/docs/develop/dynamic-content) on Swarm. It will allow you to turn Swarm into a decentralized CMS and decouple your front end from your back end.
401
+
Next, learn how to combine all the previously covered concepts to enable[dynamic content](/docs/develop/dynamic-content) on Swarm. It will allow you to turn Swarm into a decentralized CMS and decouple your front end from your back end.
0 commit comments