Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 链接到Sammy.js网站内的页面_Javascript_Jquery_Html_Sammy.js - Fatal编程技术网

Javascript 链接到Sammy.js网站内的页面

Javascript 链接到Sammy.js网站内的页面,javascript,jquery,html,sammy.js,Javascript,Jquery,Html,Sammy.js,我正在为我的网站使用Sammy.js,我想通过电子邮件向某人发送指向网站页面的链接。我已经建立了如下链接: this.get('#/', function(context) { $("#main").load("sections/home.html"); }); this.get('#/:page', function(context) { $("#main").load( "sections/" + this.params['page'] + ".html" ); }); $(do

我正在为我的网站使用Sammy.js,我想通过电子邮件向某人发送指向网站页面的链接。我已经建立了如下链接:

this.get('#/', function(context) {
  $("#main").load("sections/home.html");
});

this.get('#/:page', function(context) {
  $("#main").load( "sections/" + this.params['page'] + ".html" );
});
$(document).ready(function () {

    Sammy('#main', function() { 
            $("#header").load("templates/header.html"); 
            $("#nav-bar").load("templates/nav-bar.html"); 
            $("#footer").load("templates/footer.html");

            this.get('#/', function(context) {
              $("#main").load("sections/home.html");
            });

            this.get('#/:page', function(context) {
              $("#main").load( "sections/" + this.params['page'] + ".html" );
            });

    }).run('#/');

})
第一个是默认值,因此当您输入我的网站时,它首先进入home.html部分,如果我将其取出,当我进入我的网站时,在
#main
中不会加载任何内容。现在,如果我只是在我的URL栏中键入
mywebsite.com/#/contact
,它将直接加载到主页


我会说,如果我先进入主页,
mywebsite.com/#/
,然后将URL修改为我想要的页面,它就会工作。如果我按enter键重新加载页面,或者如果我再次尝试修改它,它将返回主页。请提供帮助。

尝试将其包装到文档中。准备好并运行默认路由-如下所示:

this.get('#/', function(context) {
  $("#main").load("sections/home.html");
});

this.get('#/:page', function(context) {
  $("#main").load( "sections/" + this.params['page'] + ".html" );
});
$(document).ready(function () {

    Sammy('#main', function() { 
            $("#header").load("templates/header.html"); 
            $("#nav-bar").load("templates/nav-bar.html"); 
            $("#footer").load("templates/footer.html");

            this.get('#/', function(context) {
              $("#main").load("sections/home.html");
            });

            this.get('#/:page', function(context) {
              $("#main").load( "sections/" + this.params['page'] + ".html" );
            });

    }).run('#/');

})

这对我来说似乎很有效。

此外,如果可能会造成干扰,我稍后会使用一点AJAX jQuery。尽管我认为我在那之前就遇到了问题。您是否在$(document.ready())中定义路由和调用run('./')?我启动main.js代码如下
Sammy('.#main',function(){$(“#header”).load(“templates/header.html”)$(“#nav bar”).load(“templates/nav bar.html”)$(“#footer”).load(“templates/footer.html”);
然后是上面的代码,然后像这样结束:
})。run();
嘿,里瓦罗,谢谢你。我已经尝试过了,但是我仍然无法在地址栏中键入页面并将其加载到正确的页面,还有什么你可能会有不同的做法吗?