简体   繁体   English

sammy.js如何存储其路由,它们是否在同一域中共享,并且可以删除?

[英]How does sammy.js store its routes, are they shared within the same domain and can they be deleted?

I have an mvc application with 2 sammy applications, 1 for the 'home' controller and 1 for the 'invoice' controller. 我有2个sammy应用程序的mvc应用程序,其中1个用于'home'控制器,另外1个用于'invoice'控制器。

I've registered a route on the 'home' and on the 'invoice' page with the path "#/about", (on both pages an new sammy application is created). 我已经在'home''invoice'页面上用路径"#/about",注册了一条路线(在两个页面上都创建了一个新的萨米应用程序)。 When I navigate to '/invoice/#about' somehow the callback on the 'home' page is called. 当我导航到'/invoice/#about'将以某种方式调用“主页”页面上的回调。 Off course, the '#/about' route should act differently on the 'home' page then on the 'invoice' page. 当然, '#/about'路线在'home'页面和'invoice'页面上的行为应有所不同。

So my question is, how does sammy store its routes and are they shared within the same domain? 所以我的问题是,sammy如何存储其路由,并且它们在同一域中共享?

Can they be deleted? 可以删除它们吗?

If not, do I need to fully destroy my application? 如果没有,我是否需要完全销毁我的应用程序?

Judging from the source code , it stores them in a javascript object only: 源代码来看,它仅将它们存储在javascript对象中:

add_route = function(with_verb) {
    var r = {verb: with_verb, path: path, callback: callback, param_names: param_names};
    // add route to routes array
    app.routes[with_verb] = app.routes[with_verb] || [];
    // place routes in order of definition
    app.routes[with_verb].push(r);
};

You can also easily check this tutorial and see that Sammy doesn't keep anything anywhere: no Web SQL, Local Storage, Cookies, etc. Nothing. 您还可以轻松地查看本教程 ,了解Sammy在任何地方都没有保存任何内容:没有Web SQL,本地存储,Cookie等。

So, the scope of routes configuration is the scope of a Sammy.Application object. 因此,路由配置的范围就是Sammy.Application对象的范围。 Obviously, it cannot exceed the lifetime of a HTML page, ie when you navigate browser to another document, the routes are dropped. 显然,它不能超过HTML页面的生存期,即,当您将浏览器导航到另一个文档时,路由将被丢弃。

Plugins might store routes, although I have no idea what the practical purpose could be. 插件可能存储路由,尽管我不知道实际的用途是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM