Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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 使用Ampersand.js路由模块化应用程序?_Javascript_Node.js_Modular_Ampersand.js - Fatal编程技术网

Javascript 使用Ampersand.js路由模块化应用程序?

Javascript 使用Ampersand.js路由模块化应用程序?,javascript,node.js,modular,ampersand.js,Javascript,Node.js,Modular,Ampersand.js,我正在尝试使用Ampersand.js编写我的第一个模块化应用程序,但我遇到了一些问题!希望有人能给我指出正确的方向 好的,我已经将Watchify和Browserify配置到我的html文件中,以创建一个bundled.js文件,每次进行更改时都会重新编译该文件。然后,我想添加一个Ampersand模块-Ampersand router(作为npm安装安装在终端中--保存Ampersand router),以指定我要处理的所有应用程序路由,并在用户遇到不可用的路由时重定向用户 问题是没有重定向

我正在尝试使用Ampersand.js编写我的第一个模块化应用程序,但我遇到了一些问题!希望有人能给我指出正确的方向

好的,我已经将
Watchify
Browserify
配置到我的html文件中,以创建一个
bundled.js
文件,每次进行更改时都会重新编译该文件。然后,我想添加一个Ampersand模块-
Ampersand router
(作为npm安装安装在终端中--保存Ampersand router),以指定我要处理的所有应用程序路由,并在用户遇到不可用的路由时重定向用户

问题是没有重定向我的#路由,我不知道为什么!因为我没有服务器(或者这个项目需要一个),我尝试使用基于#的路由,我希望它能处理三条路由,一条空路由(我的起点),
gif/id
路由一条a
catch
路由,它将重定向到起点

因此,我的文件结构包含一个router.js:-

'use strict';
var AmpersandRouter = require('ampersand-router');
module.exports = AmpersandRouter.extend({
routes:{
    '': 'gifs', //empty
    'gif/:id': 'gif',
    'catch': 'catch' //catch and redirect
},
gifs: function(){
    console.log('gifs page');
},

gif: function(id){
    console.log('gif page', id);
},
'catch': function(){
    this.redirectTo('');
}
}))

和一个app.js文件:-

var Router = require('./router.js');
window.app = {
init: function () {
    console.log('hello world');
    this.router = new Router();
    this.router.history.start();
}
};
window.app.init();
这些都是在下面我的index.html和package.json代码中汇编的

"scripts": {
"start": "watchify js/app.js -o bundled.js",
"build": "browserify js/app.js -o bundled.js"

任何帮助都将不胜感激!谢谢大家

发生了什么事?有错误吗?此外,您可以尝试跳入项目聊天并在那里询问:

您是否尝试在基本目录中使用“npm start”


我没有将Ampersand.js放入HTML文件,但它似乎可以与纯Javascript一起使用。

尝试禁用
pushState

this.router.history.start({pushState: false});
启用后,#-回退将不会生效