路由器在DurandalJS中找不到页面(Router can't find a page in DurandalJS)

编程入门 行业动态 更新时间:2024-10-24 22:21:42
路由器在DurandalJS中找不到页面(Router can't find a page in DurandalJS)

这是我的路由器配置:

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');

我可以找到/ api和其他页面,但是当我输入无效路由时,chrome控制台会给我以下内容:

我有像其他页面一样的error.js和error.html。 它位于App / viewmodels / error.js中,但我不必指定具有任何其他视图/ vms的文件夹...为什么不能找到它?

编辑每个约瑟夫的建议,我激活“错误”,我得到这个:

我很困惑...为什么它找到error.js时它已经在正确的位置找到它,为什么它认为它会在那个位置找到一个html文件?

我有一个传统的文件结构:

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:

最满意答案

结果你的问题出在error.js本身。 在Google网上论坛上请求您的文件后,我能够复制问题。

改变这个:

define(['services/dataservice'], function (dataservice) { var data = "error"; return data; })

对此:

define(['services/dataservice'], function (dataservice) { var data = "error"; return {} })

您返回的是一个字符串,在这种情况下,Durandal假定您在给定“/App/error.js”的路径上查找viewModel。 您应该返回某种类型的对象,用于绑定您的可观察对象等。

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.

更多推荐

本文发布于:2023-08-04 00:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405171.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由器   中找   页面   DurandalJS   page

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!