Custom renderer class properties
See original GitHub issueHey guys! I’m still new to the framework (moving over from Barba), and I’m running into a bit of an issue with my custom renderer class. I’m using v2.1.2, on the ES6 version of the library, and I’m using Webpack to compile and bundle my scripts.
I need to add a property to the renderer class that holds my main controller for my page scripts, so I can initialize and destroy them properly as pages are loaded and unloaded. However, if I add a constructor to the renderer, I get an Uncaught TypeError: Cannot set property 'mainController' of undefined error.
If I add a super() call before I set the property, I get this error: Uncaught TypeError: Cannot read property 'transition' of undefined at DefaultRenderer.Renderer (highway.js:2575) at new DefaultRenderer (DefaultRenderer.js:6), so obviously that doesn’t work.
Do you know how I can extend the Highway.Renderer class and add class properties?
Here’s my full custom renderer file:
import Highway from '@dogstudio/highway';
import MainController from './MainController';
class DefaultRenderer extends Highway.Renderer {
constructor() {
this.mainController = new MainController();
}
// Hooks/methods
onEnter() {
this.mainController.init();
}
onLeave() {
this.mainController.destroy();
}
onEnterCompleted() {
}
onLeaveCompleted() {
}
}
// Don`t forget to export your renderer
export default DefaultRenderer;
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)

Top Related StackOverflow Question
You could follow your logic…
… But then you have to define
defaultas the value ofdata-router-viewfor all views that should use that renderer. Doing so, the renderer will be used but you won’t be able to add extra code for a specific page.For this reason, when you need to add extra code to
DefaultRendererfor a specific view, you have to extend it and thus create another renderer that extendsDefaultRendererand add your extra code.Let’s say your contact page needs all the code from
DefaultRendererAND some extra code for this specific page. You would create aContactRendererthat would extendDefaultRendererto inherit all the code fromDefaultRendererand you could add some extra code for your contact page.Finally, to use this
ContactRendereryou have to attach it to a view name and use that name for thedata-router-viewHTML attribute like so:I hope that will help you @tiansial!
Best regards, Anthodpnt
It did, thank you!