Skip to Content
Author's profile photo Former Member

Need help in routing and passing parameters to another view ? Find it here. (Eclipse IDE)

Hello Everyone,

In this blog post we will learn how to navigate to a different view through the concept of routing and pass the data/parameters to that view.

Below is the step by step procedure:

  1. Create a new SAPUI5 application project in Eclipse IDE.

  2. In the Create a New View window, provide the initial view name and choose the type of view as XML.

  3. As we require two views to for the navigation, create another view called “SecondView” of the same type (XML).
    Note: Here we require one more view which is a kind of container of all the views in the application. Create one more view and name this view as “MainView”.

  4. After the above steps, we create an initialComponent.jsfile in theWebContentfolder that will hold our application setup. The init function of the component is automatically invoked by SAPUI5when the component is instantiated. Our component inherits from the base classsap.ui.core.UIComponentand it is obligatory to make the super call to theinitfunction of the base class in the overriddeninitmethod.

The structure of the project now looks like :

5.  Now, we are ready with the creation of all the files required, let’s go step by step and add the code in these files.


On the index page we now instantiate the component instead of the view. The helper method sap.ui.core.ComponentContainer instantiates the component by searching for a Component.js file in the namespace that is passed in as an argument. The component automatically loads the root view that we have defined above and displays it. If you now call the index.html file, the app is now packaged into a UI component.

Note : Please remember to change the path of controller in the views and controllers, since we added a property data-sap-ui-resourceroots='{“NavigationDemo”: “./”}’. Append “NavigationDemo.” before the already existing path.



<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
        controllerName="NavigationDemo.navigationdemo.FirstView" xmlns:html="">
    <Page title="Navigation Demo">
                    <Label text="Username" class="sapUiSmallMargin" />
                    <Input type="Text" placeholder="Enter the username.." id="idUserName" />
                    <Label text="Email ID" class="sapUiSmallMargin" />
                    <Input type="Email" placeholder="Enter the email id.." id="idEmail"/>
                <Button text="Go to the next view" type="Emphasized" class="sapUiSmallMargin" press="onButtonPress"/>


sap.ui.controller("NavigationDemo.navigationdemo.FirstView", {
    onInit: function() {
    onButtonPress: function(){
        //Setting the data to the model
        var username = this.getView().byId("idUserName").getValue();
        var email = this.getView().byId("idEmail").getValue();
            username: username,
            email: email
        //Navigating to second page
        var oRouter = sap.ui.core.UIComponent.getRouterFor(this);


<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
    xmlns="sap.m" controllerName="NavigationDemo.navigationdemo.SecondView"
    <Page title="Navigation Demo - Second View" showNavButton="true"
                <Text text="{Details>/username}" class="sapUiSmallMargin" />
                <Text text="{Details>/email}" class="sapUiSmallMargin" />


sap.ui.controller("NavigationDemo.navigationdemo.SecondView", {
    onNavBack: function(){
        //Navigating to second page
        var oRouter = sap.ui.core.UIComponent.getRouterFor(this);


<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
        controllerName="NavigationDemo.navigationdemo.MainView" xmlns:html="">
    <App id="app"></App>


], function(UIComponent, JSONModel){
    "use strict";
    return UIComponent.extend("NavigationDemo.Component",{
        metadata: {
            "version": "1.0.0",
            "rootView": {
                viewName: "NavigationDemo.navigationdemo.MainView",
                type: sap.ui.core.mvc.ViewType.XML
            "dependencies": {
                "libs": ["sap.ui.core", "sap.m", "sap.ui.layout"]
            "routing": {
                "config": {
                    "routerClass": "sap.m.routing.Router",
                    "viewType": "XML",
                    "viewPath": "NavigationDemo.navigationdemo",
                    "controlId": "app",
                    "controlAggregation": "pages"
                  "routes": [
                             "pattern": "",
                             "name": "firstView",
                             "target": "firstView"
                             "pattern": "secondView",
                             "name": "secondView",
                             "target": "secondView"
                "targets": {
                    "firstView": {
                          "viewName": "FirstView"
                    "secondView": {
                          "viewName": "SecondView"
        init: function(){
            UIComponent.prototype.init.apply(this, arguments);
            //Creating a JSON model
            var oModel = new JSONModel();

Working :

First view :

Second view :

Thank You

Happy Coding!

Please provide your valuable feedback.
Ashutosh Hans

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Swadhin Ghatuary
      Swadhin Ghatuary

      Good job.

      Author's profile photo rizwan pasha
      rizwan pasha

      Hi Ashu,

        Nice initiative. Hope we see more from you .



      Author's profile photo Ramazan Timur
      Ramazan Timur

      a lot of thanks 🙂