Skip to content

Commit 4e337de

Browse files
authored
📝 Update README.md
1 parent 20963ad commit 4e337de

File tree

1 file changed

+44
-12
lines changed

1 file changed

+44
-12
lines changed

README.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,35 @@ const H = new Highway.Core({
6464
}
6565
});
6666
```
67+
68+
Finally, in order to work properly **Highway** needs a basic HTML structure. All you have to do is to put somewhere in your pages the `router-wrapper` that will contain and **only** contain the `router-view`. You need to understand that **Highway** will only change the `router-view` presents in the `router-wrapper`. Everything outside of the `router-wrapper` will stay the same all along the user's navigation.
69+
70+
```html
71+
<!-- [...] -->
72+
<body>
73+
<!-- [...] -->
74+
<main router-wrapper>
75+
<article router-view>
76+
<!-- [...] -->
77+
</article>
78+
</main>
79+
<!-- [...] -->
80+
</body>
81+
<!-- [...] -->
82+
```
83+
6784
**And voilà**!
6885
You are now ready to create some beautiful and creative transitions between your pages.
6986

7087
## Renderers
7188

72-
Everytime you create a page you need to relate it to a **renderer**. This way **Highway** knows how to deal with this page's transitions. Luckily we have done **almost** all the work for you, great isn't it? However you have a part to play in this and here is how you can setup properly your renderers.
89+
Everytime you create a page that needs its own Javascript to work you need to relate it to a custom **renderer**. This way **Highway** will be able to call the page's Javascript during the transition. Luckily we have done **almost** all the work for you, great isn't it? However you have a part to play in this and here is how you can setup properly your custom renderers.
7390

74-
### HTML
91+
**Note:** If your page doesn't have any Javascript related to it you don't need to create a custom renderer for it.
7592

76-
About your HTML this is actually pretty simple... All you have to do is to put somewhere in you page the `router-wrapper` that will contain and **only** contain the `router-view` to which you are going to give a name. The name you are going to give to your `router-view` will be used later to identify it and relate it to the correct renderer in Javascript.
93+
### HTML
7794

78-
Finally what you need to understand is that **Highway** will only change the `router-view` presents in the `router-wrapper`.
79-
Everything outside of the `router-wrapper` will stay the same all along the user's navigation.
95+
About your HTML this is actually pretty simple... Remember the `router-view` you added to your DOM? You are going to name it and the name you are going to give to your `router-view` will be used later to identify it and relate it to the correct custom renderer in Javascript.
8096

8197
**index.html**
8298
```html
@@ -109,13 +125,20 @@ class Home extends Highway.Renderer {
109125
// Don`t forget to export your renderer
110126
export default Home;
111127
```
128+
112129
Besides the required methods from **Highway** present in the `Highway.Renderer` you have access to **optional** ones that are called all along the process of the navigation. Here is the list of these **optional** methods:
113130

114131
- `onEnter`: Called when the transition `in` starts & the `router-view` is added to `router-wrapper`.
115132
- `onLeave`: Called when the transition `out` starts.
116133
- `onEnterCompleted`: Called when the transition `in` is over.
117134
- `onLeaveCompleted`: Called when the transition `out` is over & the `router-view` is removed from `router-wrapper`.
118135

136+
`Highway.Renderer` also gives you access to useful variables you will be able to use in your own code:
137+
138+
- `this.page`: The full DOM of the page related to the renderer.
139+
- `this.view`: The `[router-view]` of the page related to the renderer.
140+
- `this.title`: The `document.title` of the page related to the renderer.
141+
119142
**home.js**
120143
```javascript
121144
// Import Highway
@@ -133,7 +156,7 @@ export default Home;
133156
```
134157

135158
Now your custom renderer is created you need to add it to the renderers list of `Highway.Core`...
136-
Remember the name you gave to you `router-view`, it's now time to relate it to your renderer.
159+
Remember the name you gave to you `router-view`, it's now time to relate it to your custom renderer.
137160

138161
```javascript
139162
// Import Renderers
@@ -227,22 +250,31 @@ Last but not least, **Highway** extends [**tiny-emitter**](https://github.com/sc
227250

228251
- `NAVIGATE_START`: Trigger when a navigation starts.
229252
- `NAVIGATE_END`: Trigger when a navigation ends.
253+
- `NAVIGATE_IN`: Trigger when the `in` transition starts.
254+
- `NAVIGATE_OUT`: Trigger when the `out` transition starts.
230255
- `NAVIGATE_ERROR`: Trigger when an error occurs in navigation process.
231256

232-
For the `NAVIGATE_START` and `NAVIGATE_END` events, some parameters are sent with the event in this order:
257+
All events except `NAVIGATE_ERROR` give you access to some parameters in this order:
233258

234-
- `from`: The `router-view` from the page you come from.
235-
- `to`: The `router-view` from the page you go to.
236-
- `title`: The document title of the page you go to.
259+
- `from`: The renderer of the page you come from.
260+
- `to`: The renderer of the page you go to.
237261
- `state`: The state of **Highway** that contains all the informations about the URL of the page you go to.
238262

239263
```javascript
240264
// [...]
241-
H.on('NAVIGATE_START', (from, to, title, state) => {
265+
H.on('NAVIGATE_START', (from, to, state) => {
266+
// [...]
267+
});
268+
269+
H.on('NAVIGATE_END', (from, to, state) => {
270+
// [...]
271+
});
272+
273+
H.on('NAVIGATE_IN', (from, to, state) => {
242274
// [...]
243275
});
244276

245-
H.on('NAVIGATE_END', (from, to, title, state) => {
277+
H.on('NAVIGATE_OUT', (from, to, state) => {
246278
// [...]
247279
});
248280

0 commit comments

Comments
 (0)