on 2024 Feb 02 3:00 PM
Hello experts,
I am trying to add routing to a UI5 (OpenUI5 - v1.120.3) application. I have followed the Walkthrough tutorial on UI5 Demo kit site. On step number 30, I have added routing config in manifest.json, initialized router in Component.js, and made sure that all views are in their proper expected place.
I am using the UI5 CLI (v3.2.0) to develop the application. Before the routing step everything was working as expected. When I run the app with routing (as per step 30) the page goes blank and I see these warnings in browser console,
No matter what I do, nothing works. I downloaded and started the step 30 code and to my surprise that code also gives me these warnings but the page comes up and routing works.
The only difference in both the code bases is that I am instantiating ComponentContainer from index.js file instead of doing it from index.html file. But I don't think it should matter since everything else works.
Can someone please guide as to what I may be missing here.
Request clarification before answering.
I found the issue and its resolution. It was caused by the auto-complete feature of VSC extension - "UI5 Language Assistant".
The correct routing config in manifest.json is (notice the "path" property):
The routing config options as suggested by auto-complete is (notice the "viewPath" property):
Once I changed it to "path" instead of "viewPath" it was resolved. I am opening an issue in the extension's Github repo to track it officially.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
paste the important code here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>UI5 Training app</title>
<script
id="sap-ui-bootstrap"
src="resources/sap-ui-core.js"
data-sap-ui-theme="sap_horizon"
data-sap-ui-libs="sap.m"
data-sap-ui-compatVersion="edge"
data-sap-ui-async="true"
data-sap-ui-onInit="module:ui5/training/index"
data-sap-ui-resourceroots='{
"ui5.training": "./"
}'>
</script>
</head>
<body class="sapUiBody" id="content">
<!-- <div data-sap-ui-component data-name="ui5.training" data-id="container" data-settings='{"id" : "training"}'></div> -->
<!-- <div>Hello World</div> -->
</body>
</html>
index.js
sap.ui.define([
"sap/ui/core/ComponentContainer"
], (ComponentContainer) => {
"use strict";
new ComponentContainer({
name: "ui5.training",
id: "container",
settings : {
id : "training"
},
async: true
}).placeAt("content");
});
Component.js
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/model/json/JSONModel"
], (UIComponent, JSONModel) => {
"use strict";
return UIComponent.extend("ui5.training.Component", {
metadata: {
"interfaces": ["sap.ui.core.IAsyncContentCreation"],
"manifest": "json"
},
init() {
UIComponent.prototype.init.apply(this, arguments);
const oData = {
user : {
name : "John"
}
};
const oModel = new JSONModel(oData);
this.setModel(oModel);
this.getRouter().initialize();
}
});
});
manifest.json
"sap.ui5": {
...
"rootView": {
"viewName": "ui5.training.view.App",
"type": "XML",
"id": "app"
},
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "ui5.training.view",
"controlId": "app",
"controlAggregation": "pages"
},
"routes": [
{
"pattern": "",
"name": "overview",
"target": "overview"
},
{
"pattern": "detail",
"name": "detail",
"target": "detail"
}
],
"targets": {
"overview": {
"id": "overview",
"name": "Overview"
},
"detail": {
"id": "detail",
"name": "Detail"
}
}
}
}
App.view.xml
<mvc:View xmlns="sap.m" controllerName="ui5.training.controller.App"
xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core">
<Shell>
<App id="app" class="myApp" />
</Shell>
</mvc:View>
Overview.view.xml
<mvc:View
controllerName="ui5.training.controller.App" displayBlock="true"
xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core">
<Page title="{i18n>homePageTitle}" class="sapUiSizeCozy">
<content>
<Button text="Test button" />
</content>
</Page>
</mvc:View>
These are the main files related to this problem. I can see the Shell when the app runs but the Overview page doesn't load.
User | Count |
---|---|
66 | |
9 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.