routing : {
config : {
routerClass : com.pdh.MyRouter,
viewType : "XML",
viewPath : "com.pdh.view",
targetAggregation : "detailPages",
clearTarget : false
},
routes : [
{
pattern : "",
name : "main",
view : "Master",
targetAggregation : "masterPages",
targetControl : "idAppControl",
subroutes : [
{
pattern : "{product}/:tab:",
name : "product",
view : "Detail"
}
]
},{
pattern : "detail1",
name : "detail1",
view : "Detail1",
targetAggregation : "detailPages",
targetControl : "idAppControl"
},
{
name : "catchallMaster",
view : "Master",
targetAggregation : "masterPages",
targetControl : "idAppControl",
subroutes : [
{
pattern : ":all*:",
name : "catchallDetail",
view : "NotFound",
transition : "show"
}
]
}
]
}
添加按钮的主视图
<mvc:View controllerName="com.pdh.view.Master"
displayBlock="true" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m">
<Page id="page" title="{i18n>masterTitle}">
<subHeader>
<Bar id="searchBar">
<contentMiddle>
<!-- <SearchField id="searchField" showRefreshButton="{device>/isNoTouch}"
search="onSearch" tooltip="{i18n>masterSearchTooltip}" width="100%"> </SearchField> -->
</contentMiddle>
</Bar>
</subHeader>
<content>
<Button xmlns="sap.m" busy="false" busyIndicatorDelay="1000"
visible="true" text="Jun" type="Default" width="" enabled="true"
icon="" iconFirst="true" activeIcon="" iconDensityAware="true"
ariaDescribedBy="" ariaLabelledBy="" tap="" press="junNav">
<tooltip></tooltip> <!-- sap.ui.core.TooltipBase -->
<dependents></dependents> <!-- sap.ui.core.Control, since 1.19 -->
</Button>
<!-- <List id="list" items="{/}" mode="{device>/listMode}"
noDataText="{i18n>masterListNoDataText}" select="onSelect" growing="true"
growingScrollToLoad="true">
<items>
<ObjectListItem type="{device>/listItemType}" press="onSelect"
title="{product_cd}">
</ObjectListItem>
</items>
</List> -->
</content>
<footer>
<Bar>
<contentRight>
<Button icon="sap-icon://add" tooltip="{i18n>masterFooterAddButtonTooltip}"
press="onAddProduct" />
</contentRight>
</Bar>
</footer>
</Page>
控制器中的事件处理程序
junNav : function() {
// This is only relevant when running on phone devices
console.log("junNav");
this.getRouter().navTo("detail1",null,true);
},
routepatternmatched事件的事件处理程序
onRouteMatched : function(oEvent) {
var sName = oEvent.getParameter("name");
console.log("master controller onRouteMatched "+sName);
if (sName !== "main") {
return;
}
//Load the detail view in desktop
this.getRouter().myNavToWithoutHash({
currentView : this.getView(),
targetViewName : "com.pdh.view.Detail",
targetViewType : "XML"
});
//Wait for the list to be loaded once
this.waitForInitialListLoading(function () {
//On the empty hash select the first item
this.selectFirstItem();
});
},
答案 0 :(得分:1)
使用路由时,路由的顺序很重要。 只有匹配模式的第一条路线才会触发事件。 yout route product有一个与detail1匹配的模式 自{product} /:标签: 将导致细节/(无标签)
如果您将此模式更改为Products / {product}:标签 detail1将不再匹配 产品/细节1将匹配。
祝你好运, 托拜厄斯