Skip to Content

difference between routeMatched and routePatternMatched events in sap.ui.core.routing.Router

hi to all,

i am not getting clearly the difference between the routeMatched and routePatternMatched

when i am checking these two events got triggered in an init method in a router.

when we have to use attachrouteMatched() ?

and when we have to use attachroutePatternMatched() ?

both are almost giving the same output.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Feb 20, 2017 at 06:32 PM

    The difference between the two is when they are fired.

    attachrouteMached is fired under the below three instances:

     a. the pattern of a route inthis router.
     b. the pattern of its sub-route.
     c. the pattern of its nested route.Whenthis occurs, the 'nestedRoute' parameter issetwith the instance of nested route.

    attachroutePatternMatched() is only fired when the current URL hash matches the pattern of the router.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 23, 2017 at 07:06 AM

    lets have an example,

    suppose routing we have like below:

    "routes": [{
        "pattern": "Details/{path}",
        "name": "detailPage",
        "target": "detailPage"
    }],
    "targets": {
        "detailPage": {
            "viewName": "DetailPage",
            "viewId": "detailPage",
            "viewLevel": 2
        }
    }

    attachPatternMatched function will be called for particular pattern determined by target say "detailPage", see below example,

    this.getRouter().getRoute("detailPage").attachPatternMatched(this._onObjectMatched, this); 
    _onObjectMatched: function(oEvent) { 
     // binding view code and all
    },

    in above example _onObjectMatched will be called only when for pattern which belongs to target "detailPage" .

    Whereas:

    this._oRouter.attachRoutePatternMatched(this._onRoutePatternMatched, this);
    _onRoutePatternMatched: function(oEvent) {
        if (oEvent.getParameter("name") !== "detailPage") {
            return;
        }
      // binding view logic and all
    },

    in above example, attachRoutePatternMatched will be called whenever app navigated to detail page, but you need to check whether particular pattern matched for name "detailPage" or not.

    I may not be the perfect but hope this help :)

    Thanks,

    Akhilesh

    Add comment
    10|10000 characters needed characters exceeded