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: README.md
+44-12Lines changed: 44 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,19 +64,35 @@ const H = new Highway.Core({
64
64
}
65
65
});
66
66
```
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
+
<mainrouter-wrapper>
75
+
<articlerouter-view>
76
+
<!-- [...] -->
77
+
</article>
78
+
</main>
79
+
<!-- [...] -->
80
+
</body>
81
+
<!-- [...] -->
82
+
```
83
+
67
84
**And voilà**!
68
85
You are now ready to create some beautiful and creative transitions between your pages.
69
86
70
87
## Renderers
71
88
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.
73
90
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.
75
92
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
77
94
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.
80
96
81
97
**index.html**
82
98
```html
@@ -109,13 +125,20 @@ class Home extends Highway.Renderer {
109
125
// Don`t forget to export your renderer
110
126
exportdefaultHome;
111
127
```
128
+
112
129
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:
113
130
114
131
-`onEnter`: Called when the transition `in` starts & the `router-view` is added to `router-wrapper`.
115
132
-`onLeave`: Called when the transition `out` starts.
116
133
-`onEnterCompleted`: Called when the transition `in` is over.
117
134
-`onLeaveCompleted`: Called when the transition `out` is over & the `router-view` is removed from `router-wrapper`.
118
135
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
+
119
142
**home.js**
120
143
```javascript
121
144
// Import Highway
@@ -133,7 +156,7 @@ export default Home;
133
156
```
134
157
135
158
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.
137
160
138
161
```javascript
139
162
// Import Renderers
@@ -227,22 +250,31 @@ Last but not least, **Highway** extends [**tiny-emitter**](https://github.com/sc
227
250
228
251
-`NAVIGATE_START`: Trigger when a navigation starts.
229
252
-`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.
230
255
-`NAVIGATE_ERROR`: Trigger when an error occurs in navigation process.
231
256
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:
233
258
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.
237
261
-`state`: The state of **Highway** that contains all the informations about the URL of the page you go to.
238
262
239
263
```javascript
240
264
// [...]
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) => {
242
274
// [...]
243
275
});
244
276
245
-
H.on('NAVIGATE_END', (from, to, title, state) => {
0 commit comments