忽略DurandalJS应用中的锚点 [英] Ignore an anchor in DurandalJS app

查看:81
本文介绍了忽略DurandalJS应用中的锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用DurandalJS的SPA应用程序,效果很好.链接已路由,视图模型已激活等.

I have an SPA app using DurandalJS that works great. Links are routed, view models are activated, etc.

问题是,我有一个锚点指向实际存在于服务器上的页面.我需要浏览器才能实际查询该页面(这是一个asp.net MVC页面).

The problem is, I have an anchor that points to a page that actually lives on the server. I need the browser to actually query this page (it's an asp.net MVC page).

Durandal中的路由器似乎挂接到相对的所有链接(或实际上在同一域中),如果找不到路由,则调用路由器的handleInvalidRoute方法.

It seems the router in Durandal hooks into all links that are relative (or on the same domain, really) and if it finds no route, calls the handleInvalidRoute method of router.

我一生无法解决如何告诉Durandal不要路由此URL的问题.我还需要保留中/ctrl + click功能.

I cannot for the life of me figure out how to tell Durandal to not route this URL. I need to keep middle / ctrl+click functionality as well.

文档无济于事,Google却一无所获.我也尝试研究一下路由器/SammyJs代码,但是看不到任何明显的东西.

Documentation is no help and google has turned up nothing. I also tried to look into the router / SammyJs code, but I couldn't see anything obvious.

这个问题似乎是相同的作为我的,但答案对我不起作用.我的网址都是实际的网址(不带哈希前缀),因此我无法关闭PushState.

This question seems to be the same as mine, but the answer does not work for me. My URLs are all actual URLs (not hash-prefixed) so I can't turn off PushState.

推荐答案

到目前为止,我发现的最简单的方法是创建一个绝对URL(例如,

The easiest way I found so far was to create an absolute url (e.g. http://myapp.com/whatever-that-is-not-a-sammy-route) and add

target="_top"

锚点.这样可以启用新标签页行为(按住Ctrl键单击,单击中键,打开新标签页上下文菜单),并在单击链接时在当前窗口中打开它,从而绕过Sammy路由!

to the anchor. This allows new tab behavior (ctrl+click, middle click, open new tab context menu) and when the link is left clicked, it opens in the current window, bypassing Sammy routing!

这篇关于忽略DurandalJS应用中的锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆