链接用热毛巾和迪朗达尔另一个控制器 [英] link to another controller with hot towel and durandal

查看:143
本文介绍了链接用热毛巾和迪朗达尔另一个控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发有多个水疗中心的一个mvc4应用。

I am developing an mvc4 app with multiple spa's.

我是用我的水疗热毛巾模板。

I am using the hot towel template for my spa.

我想要做的是有我的水疗中心的意见中的锚链接到另一个控制器指数的动作,所以我的用户可以关闭一个水疗中心并打开另一个。并非所有的行动将启动一个水疗有些是正规MVC样式的网页。

What I want to do is have a anchor link within my views for a spa go to the index action for another controller, so my users can exit one spa and open another. Not all actions will start a spa some are regular mvc style pages.

我已经把code一样喜欢在我的水疗中心的HTML页面如下:

I have put code like like the following in my spa html pages:

<a href="/controller/action">Navigate to another controller</a>

这将改变浏览器的URL,但始终重新加载默认的HTML页面的水疗中心。如果我打了浏览器的刷新按钮,这时如果将前往正确的页面。

This will change the url in the browser but always reloads the default html page for the spa. If I hit the refresh button in the browser then if will go to the proper page.

我已经能够把一个目标上_parent的定位标记或_top这样的:

I have been able to put a target on the anchor tag of _parent or _top like:

 <a href="/controller/action" target="_parent">Navigate to another controller</a>

和将导航到新的控制器页面。

and it will navigate to the new controller page.

我相信这是一些在迪朗达尔框架,$ P $从导航到第二个控制器pventing水疗中心,但因为我刚开始这个工作,我难倒我需要改变。我认为应该有比锚标记使用目标更好的方法,或者是最好的选择。

I believe it is something in the durandal framework that is preventing the spa from navigating to the second controller, but since I am just starting to work with this, I am stumped as what I need to change. I think there should be a better way than using the target in the anchor tag, or is that the best option.

推荐答案

我希望我正确地理解你。我认为这种行为是引起了我Sammy.js(其中迪朗达尔路由器目前基于)。萨米的默认行为是劫持的所有链接,并处理它们至于到SPA本身。

I hope that I have understood you correctly. I believe this behaviour is caused my Sammy.js (which the durandal router is currently based on). The default behaviour of Sammy is to hijack all links and process them as regards to the SPA itself.

我不喜欢这种行为的网站我的工作,需要链接到其他的MVC Web页面可以从水疗中心内。我真正想要的是常规链接只是工作和散列连接是PTED为纽带,以水疗中心内的另一个视角间$ P $。因此,/控制器/动作会去到另一个网页和#moduleId'会去另一个迪朗达尔V / VM。

I didn't like this behaviour for the website I am working on and needed links to other MVC web pages to be possible from within the SPA. What I really wanted is for regular links to just work and hash links to be interpreted as a link to another view within the SPA. So '/controller/action' would go to another web page and '#moduleId' would go to another durandal V/VM.

我发现对我的作品此萨米选项,并设置它在我的main.js

I found this Sammy option that works for me and set it in my main.js

    // This stops Sammy from hijacking regular links
    Sammy.Application.prototype.disable_push_state = true;

这篇关于链接用热毛巾和迪朗达尔另一个控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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