带有XML视图的SapUI5路由器问题

带有XML视图的SapUI5路由器问题,sapui5,Sapui5,我正在开发一个简单的UI5项目,以便能够了解路由器的工作原理。。在这个过程中,我面临一个与路由器事件相关的问题。我有三个XML视图,分别是第一页、第二页和第三页。第三个页面在其他两个页面中实现,如下代码所示: <mvc:XMLView viewName="SapUI5Tutorial.Application.Main.views.ThirdPage.view.ThirdPage"/> })) 如何防止运行第三页的两次路由器事件?感谢您的帮助因为您在第一页中有第三页视图,所以第三页不

我正在开发一个简单的UI5项目,以便能够了解路由器的工作原理。。在这个过程中,我面临一个与路由器事件相关的问题。我有三个XML视图,分别是第一页、第二页和第三页。第三个页面在其他两个页面中实现,如下代码所示:

<mvc:XMLView viewName="SapUI5Tutorial.Application.Main.views.ThirdPage.view.ThirdPage"/>
}))


如何防止运行第三页的两次路由器事件?感谢您的帮助

因为您在第一页中有第三页视图,所以第三页不需要其他模式匹配功能


更糟糕的是,我认为没有必要为第三页视图设置单独的控制器。您可以并且应该重用父FirstView的控制器。

我认为您的问题在于使用
.attachMatched
而不是
。attachPatternMatched

前者为任何路线或子线路点火,而后者仅为子线路点火


文档对此不是很清楚,但是可以找到。

你说得对,但是当我回到第一页时,第三页的init函数没有被触发(init函数不工作。它只触发了一次),因为它以前已经加载过。如何再次触发ThirdPage的Init函数?这有帮助吗?sap.ui.getCore();
<mvc:View displayBlock="true" controllerName="SapUI5Tutorial.Application.Main.views.FirstPage.controller.FirstPage"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
xmlns:l="sap.ui.layout"
xmlns="sap.m" height="100%">
<Page title="First Page" class="sapUiNoContentPadding">
    <subHeader>
        <Toolbar>
            <VBox width="100%" alignItems="Center">
                <Button text="Second Page Link" press="handleNavSecondPage"/>
            </VBox>
        </Toolbar>
    </subHeader>
    <mvc:XMLView viewName="SapUI5Tutorial.Application.Main.views.ThirdPage.view.ThirdPage"/>
</Page>
sap.ui.define([
"sap/ui/core/mvc/Controller",
], function (Controller, FragmentController) {
"use strict";
var base, oRouter;
return Controller.extend("SapUI5Tutorial.Application.Main.views.ThirdPage", {
    onInit: function () {
        base = this;
        base.getView().setModel(oModel);
        oRouter = sap.ui.core.UIComponent.getRouterFor(base);
        oRouter.getRoute("FirstPage").attachMatched(base.firstPagePatternMatched, base);
        oRouter.getRoute("SecondPage").attachMatched(base.secondPagePatternMatched, base);
    },
    firstPagePatternMatched: function (oEvent) {
        console.log(oEvent)
    },
    secondPagePatternMatched: function (oEvent) {
        //Due to the third page is used for inside two other pages (FirstPage and SecondPage) this function is running twice
        console.log(oEvent)
    }
});