Here's my router configuration:
router.useConvention();
router.mapRoute('error', 'viewmodels/error', "Error");
router.mapNav('home');
router.mapRoute('api', 'viewmodels/api', 'API Reference');
router.mapRoute('set/:id', 'viewmodels/set', 'Set');
router.mapRoute('folder/:id', 'viewmodels/folder', 'Folder');
router.handleInvalidRoute = function (route, params) {
//debugger;
router.navigateTo('#/error');
};
logger.log('app has loaded :)', null, null, false);
return router.activate('home');
I can find /api and other pages, but when I type in an invalid route, the chrome console gives me the following:
I have error.js and error.html just like the other pages. It's in App/viewmodels/error.js, but I don't have to specify the folder with any other views/vms... why isn't it being found?
EDIT Per Joseph's suggestion, I activated on "error" and I get this:
I'm so confused... why is it looking for error.js when it already found it in the correct location, and why does it think it's going to find an html document at that location?
I have a conventional file structure:
It turn's out your issue is in error.js itself. After requesting your files on Google Groups, I was able to duplicate problem.
Change this:
define(['services/dataservice'], function (dataservice) {
var data = "error";
return data;
})
to this:
define(['services/dataservice'], function (dataservice) {
var data = "error";
return {}
})
You were returning a string in which case Durandal assumes you are looking for a viewModel at the path given "/App/error.js". You should be returning an object of some sort that you will use to bind your observables, etc.
添加以下代码:router.mapRoute('pagenotfound','viewmodels / pagenotfound','找不到页面',false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.