Freigeben über


WinJS Grid Template – overriding load causes HierarchyRequestError

Interesting query I responded to recently regarding WinJS apps and the base JavaScript / Grid template.  The person wanted to preload some data in the load method before running the page.  Makes sense….

Basically the coder simply created a new Grid template application.

Then they went into the groupDetail.js and added in a load handler as follows:

load: function ()
{
},

Simply running the app, navigating to a groupDetail page, navigating back, then navigating once again to groupDetail.js would cause the app to kick into the default.js terminateAppHandler with a HierarchyRequestError in the debug output Window.

If we take a look at the docs for the load override at https://msdn.microsoft.com/en-us/library/windows/apps/Hh770588.aspx  we can see that, as the API is defined, you are required to return a promise for the content.  Unfortunately the nice stock sample they have didn’t work for me.  The following snippet below, however, did work admirably for the Grid Template.

load: function ()
{
// do other stuff
var a = document.createElement("a");
a.href = WinJS.Navigation.location;
return WinJS.UI.Fragments.renderCopy(a.href.toLowerCase());
},

That was my solution, put here in hopes that the SEO gods will keep this in the top of the cache for other folks out there.   Anyone else ran into this and implemented it differently?