Skip to Content
0
Aug 17, 2015 at 01:03 PM

a question about router

18 Views

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>