cancel
Showing results for 
Search instead for 
Did you mean: 

a question about router

raffinkira
Participant
0 Kudos

Hi all,

I get stuck for page navigation by using router . I have read the walkthrough 31 and I think I did exactly the same.

Yet I cannot work it out. Can anyone help me out with that? Here is the code.

I have two pages which are named as Login.view.xml and Home.view.xml.

manifest.json:

"routing":
{
    "config":
{
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "lxfym.view",
"controlId": "app",
"controlAggregation": "pages"
},
"routes":
[
{
  "pattern": "",
  "name": "login",
  "target": "login"
},
{
"pattern": "home",
    "name": "home",
    "target": "home"
}
],
"targets":
{
"login":
{
"viewName": "Login"
},
"home":
{
"viewName": "Home"
}
}
}

Component.js:

this.getRouter().initialize();

App.xml.view

<mvc:View

controllerName="lxfym.controller.App"

xmlns="sap.m"

xmlns:mvc="sap.ui.core.mvc"

displayBlock="true">

<App class="login" id="app"/>

</mvc:View>

Login.xml.view

<mvc:View

controllerName="lxfym.controller.Login"

xmlns="sap.m"

xmlns:mvc="sap.ui.core.mvc"

>

<Page

title="{i18n>login_page_title}"

width="auto">

<content>

<Button

text="Login"

press="onLogin"

class="login"/>

</content>

</Page>

</mvc:View>

Login.controller.js

        onLogin : function (oEvent)
        {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("Home");
        }

Home.view.xml

<mvc:View

controllerName="lxfym.controller.Home"

xmlns="sap.m"

xmlns:mvc="sap.ui.core.mvc">

<Page

title="{i18n>home_page_title}"

width="auto">

<content>

</content>

</Page>

</mvc:View>

Accepted Solutions (0)

Answers (2)

Answers (2)

preetamr
Explorer
0 Kudos

Login.controller.js

                onLogin : function (oEvent)  

                {  

                var oRouter = sap.ui.core.UIComponent.getRouterFor(this);

                oRouter.navTo("Home");

                }

Login.controller.js


  onLogin : function (oEvent)  

                {  

                var oRouter = sap.ui.core.UIComponent.getRouterFor(this);

                oRouter.navTo("home"); //routing configuration has "home" not "Home"

                }

Best regards,

Preetam

Former Member
0 Kudos

Thank you for both. After trying what you told me, it worked.

I wrote this code by following the walkthrough step 31 exactly, so I think it maybe make a mistake.

OpenUI5 SDK - Demo Kit

Former Member
0 Kudos

Hi,

In your login controller you are using navTo('Home') but in routes definition its defined with small "home".

-Zuber