OJET: Bug with Routing in TypeScript Template

Oracle JET supports officially TypeScript for your application development.
OJET CLI does NOT include templates which uses by default TypeScript.
However, in the Oracle website they provide an starting point template in case you want to use TypeScript.

JET TypeScript Starter Template - Web NavBar

In my GitHub you can find the app fixed: (ojet-typescript-template)
https://github.com/DanielMerchan/ojet-examples


The application has a minor bug in its Router configuration which makes the following strange behaviour:

If you copy any module URL such as http://localhost:8000/?root=incidents in your browsers it always load the default module which is the dashboard



Why? How to fix it?

In the TypeScript template there is a duplication of the Router configuration. You can find a self.router.configure in:
  • root.ts which acts as the "main.js" of the Oralce JET Out-of-the-box basic templates created with OJET CLI
  • appController.ts which is the appController.js of the Oralce JET Out-of-the-box basic templates created with OJET CLI
To fix it:
  1. Remove the configuration of the Router in root.ts
  2. Initialise the Router before to apply the bindings.
  3. Apply the bindings with the new created variable

    import * as ko from "knockout";
    import "ojs/ojknockout";
    import RootViewModel = require ('./appController');
    import Router = require('ojs/ojrouter');
    import Logger = require('ojs/ojlogger');
    
    class Root {
        router: Router;
    
        constructor() {
            let self = this;
            self.router = Router.rootInstance;
            const rootVM = new RootViewModel();
            Router.defaults['urlAdapter'] = new Router.urlParamAdapter();
            Router.sync().then(
                function() {
                    // bind your ViewModel for the content of the whole page body.
                    ko.applyBindings(rootVM, document.getElementById('globalBody'));
                },
                function(error) {
                    Logger.error('Error in root start: ' + error.message);
                }
            );
        }
    }
    
    export = Root;

Comments

Post a Comment

Popular posts from this blog

OJET: Inter-Module communication in TypeScript Template

OJET: Build and Deploy in an Application Server

OJET: Select All options using only Checkboxset