Copy edit docs
This commit is contained in:
parent
ea0b661b79
commit
9ea782f759
19 changed files with 100 additions and 98 deletions
|
|
@ -1,6 +1,6 @@
|
|||
## Routing
|
||||
|
||||
Routing is a system that allows creating Single-Page-Applications (SPA), i.e. applications that can go from a page to another without causing a full browser refresh.
|
||||
Routing is a system that allows creating Single-Page-Applications (SPA), i.e. applications that can go from one page to another without causing a full browser refresh.
|
||||
|
||||
It enables seamless navigability while preserving the ability to bookmark each page individually, and the ability to navigate the application via the browser's history mechanism.
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ Mithril provides utilities to handle three different aspect of routing:
|
|||
|
||||
To define a list of routes, you need to specify a host DOM element, a default route and a key-value map of possible routes and respective [modules](mithril.module.md) to be rendered.
|
||||
|
||||
The example below defines 3 routes, to be rendered in `<body>`. `home`, `login` and `dashboard` are modules. We'll see how to define a module in a bit.
|
||||
The example below defines three routes, to be rendered in `<body>`. `home`, `login` and `dashboard` are modules. We'll see how to define a module in a bit.
|
||||
|
||||
```javascript
|
||||
m.route(document.body, "/", {
|
||||
|
|
@ -26,9 +26,9 @@ m.route(document.body, "/", {
|
|||
});
|
||||
```
|
||||
|
||||
Routes can take arguments, by prefixing words with a colon `:`
|
||||
Routes can take arguments, by prefixing words with a colon `:`.
|
||||
|
||||
The example below shows a route that takes an `userID` parameter
|
||||
The example below shows a route that takes a `userID` parameter.
|
||||
|
||||
```javascript
|
||||
//a sample module
|
||||
|
|
@ -56,13 +56,13 @@ This redirects to the URL `http://server/#/dashboard/johndoe` and yields:
|
|||
<body>johndoe</body>
|
||||
```
|
||||
|
||||
Above, `dashboard` is a module. It contains a `controller` and a `view` properties. When the URL matches a route, the respective module's controller is instantiated and passed as a parameter to the view.
|
||||
Above, `dashboard` is a module. It contains `controller` and `view` properties. When the URL matches a route, the respective module's controller is instantiated and passed as a parameter to the view.
|
||||
|
||||
In this case, since there's only route, the app redirects to the default route `"/dashboard/johndoe"` and, under the hood, it calls `m.module(document.body, dashboard)`.
|
||||
In this case, since there's only one route, the app redirects to the default route `"/dashboard/johndoe"` and, under the hood, it calls `m.module(document.body, dashboard)`.
|
||||
|
||||
The string `johndoe` is bound to the `:userID` parameter, which can be retrived programmatically in the controller via `m.route.param("userID")`.
|
||||
The string `johndoe` is bound to the `:userID` parameter, which can be retrieved programmatically in the controller via `m.route.param("userID")`.
|
||||
|
||||
The `m.route.mode` property defines which URL portion is used to implement the routing mechanism. Its value can be set to either "search", "hash" or "pathname". The default value is "search"
|
||||
The `m.route.mode` property defines which URL portion is used to implement the routing mechanism. Its value can be set to either "search", "hash" or "pathname". The default value is "search".
|
||||
|
||||
- `search` mode uses the querystring. This allows named anchors (i.e. `<a href="#top">Back to top</a>`, `<a name="top"></a>`) to work on the page, but routing changes causes page refreshes in IE8, due to its lack of support for `history.pushState`.
|
||||
|
||||
|
|
@ -72,18 +72,18 @@ The `m.route.mode` property defines which URL portion is used to implement the r
|
|||
|
||||
Example URL: `http://server/#/path/to/page`
|
||||
|
||||
- `pathname` mode allows routing URLs that contains no special characters, however this mode requires server-side setup in order to support bookmarking and page refreshes. It also causes page refreshes in IE8.
|
||||
- `pathname` mode allows routing URLs that contain no special characters, however this mode requires server-side setup in order to support bookmarking and page refreshes. It also causes page refreshes in IE8.
|
||||
|
||||
Example URL: `http://server/path/to/page`
|
||||
|
||||
The simplest server-side setup possible to support pathname mode is to serve the same content regardless of what URL is requested. In Apache, this URL rewriting can be achieved using ModRewrite.
|
||||
The simplest server-side setup possible to support pathname mode is to serve the same content regardless of what URL is requested. In Apache, this URL rewriting can be achieved using [mod_rewrite](https://httpd.apache.org/docs/current/mod/mod_rewrite.html).
|
||||
|
||||
|
||||
---
|
||||
|
||||
### Redirecting
|
||||
|
||||
You can programmatically redirec to another page. Given the example in the "Defining Routes" section:
|
||||
You can programmatically redirect to another page. Given the example in the "Defining Routes" section:
|
||||
|
||||
```javascript
|
||||
m.route("/dashboard/marysue");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue