2013-04-04 113 views
1

我试图在一个由node.js服务器支持的AngularJS应用程序中使用express来设置一些参数路由。节点设置路由的一切,没有明确地发现包罗万象:Express.js和AngularJS路由参数

app.use(express.bodyParser()); 
app.use(app.router); 
app.use(express.static(__dirname + "/public")); 
app.use(function(request, response) 
{ 
    console.log("catch all"); 
    writeFile("/public/index.htm", request, response); 
}); 

和角度有路线有0-2个参数定义的:

$routeProvider 
.when("/", 
{ 
    templateUrl: "home.htm" 
}) 
.when("/otherpage", 
{ 
    templateUrl: "otherpage.htm" 
}) 
.when("/otherpage/:Var1", 
{ 
    templateUrl: "otherpage.htm" 
}) 
.when("/otherpage/:Var1/:Var2", 
{ 
    templateUrl: "otherpage.htm" 
}) 
.otherwise(
{ 
    templateUrl: "home.htm" 
}); 

$locationProvider.html5Mode(true); 

/otherpage作品,但同时/ otherpage/123击中所有(我可以看到控制台消息),它在浏览器中崩溃。什么都没有呈现,然后Chrome说它有问题(IE浏览器没有呈现任何内容)。

我可以理解参数没有被传递,但为什么不是没有它的路线呢?我需要做些什么来设置express.js和AngularJS的URL参数?

如果你想检查它,你可以下载项目here

在此先感谢。

+0

我强烈建议使用Brian Fords优秀的Angular-Express-Seed作为您的出发点。看看https://github.com/btford/angular-express-seed。作为Node和Angular的新手,我已经在自己的项目中使用过它,并发现它非常宝贵。 – supermasher 2013-04-04 10:13:44

回答

2

问题在于我没有在预览模板的前面加上预见。将它们更改为:

.when("/otherpage/:Var1/:Var2", 
{ 
    templateUrl: "/otherpage.htm" 
}) 

完美工作。