SAP ui 5 router error when initiating the sap.f.router

584 Views Asked by At

I got an error when initiating sap ui program, please help

manifest.json

"sap.ui5": {
    "rootView": {
        "viewName": "latihan1.view.App",
        "type": "XML"
    },
    "dependencies": {
        "minUI5Version": "1.30.0",
        "libs": {
            "sap.ui.core": {},
            "sap.m": {},
            "sap.f": {},
            "sap.ui.layout": {}
        }
    },
    "config": {
        "fullWidth": true
    },
    "contentDensities": {
        "compact": true,
        "cozy": true
    },

and index.html

<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta charset="UTF-8">

        <title>latihan1</title>

        <script id="sap-ui-bootstrap"
            src="../../resources/sap-ui-core.js"
            data-sap-ui-libs="sap.ui.core, sap.m, sap.f, sap.ui.layout"
            data-sap-ui-theme="sap_belize"
            data-sap-ui-compatVersion="edge"
            data-sap-ui-resourceroots='{"latihan1": ""}'>
        </script>

and component.js

sap.ui.define([
    "sap/ui/core/UIComponent",
    "sap/ui/Device",
    "latihan1/model/models",
    "sap/f/library"
], function(UIComponent, Device, models, library) {
    "use strict";

    return UIComponent.extend("latihan1.Component", {

        metadata: {
            manifest: "json"
        },

        /**
         * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
         * @public
         * @override
         */
        init: function() {
            // call the base component's init function
            UIComponent.prototype.init.apply(this, arguments);
            
            // enable routing
            this.getRouter().initialize();

            // set the device model
            this.setModel(models.createDeviceModel(), "device");
        }
    });

enter image description here

The library already loaded

enter image description here

1

There are 1 best solutions below

2
fabiopagoti On

You can remove the sap/f/library inside the dependencies of your Component. Can you try that? Having them in the manifest inside the libs is enough. You don't even need those inside the index file as well.

However what seems be missing in your manifest.json file is the router class under sap.ui5 section.

"routing": {
    "config": {
        "routerClass": "sap.f.routing.Router"
    }