防爆preSS +角路由造成无限循环+崩溃路由、preSS

2023-09-13 03:08:18 作者:┊浅末年华┊

我正在使用防爆preSS以及角节点的应用程序。我使用的角度进行路由选择,并有我的路线设置像这样:

 的app.config(['$ routeProvider',函数($ routeProvider){$ routeProvider.when('/',{    templateUrl:'/谐音/主    //控制器:'IndexController中})时​​,('/发现',{    templateUrl:'/谐音/发现})时​​,('/用户/家',{//继承人的问题儿童!!!!!    templateUrl:'/谐音/用户/家})。除此以外({    redirectTo:'/'});}])。配置(['$ locationProvider',函数($ locationProvider){    $ locationProvider.html5Mode(真);}]); 

现在,每当我尝试并调用 /用户/家庭 - 页面进入一个无限循环并保持重装控制器。我可以在页面从的谐音/用户/家庭这无疑包含了一个玉文件调用的节点控制台中看到。我检查了其他职位,大部分都是用屁股解决了 / 的谐音路径的开始,这并没有任何帮助。页面加载,如果我精调 home.jade /谐音目录中没有子目录。任何想法?

更新:似乎无限循环发生只要我尝试加载部分中谐音的任何子目录

每请求:

节点 - App.js:

  app.get('/',routes.index);app.get('/谐音/:名称',routes.partials);app.get('*',routes.index); 

和路线/ index.js

  exports.index =功能(REQ,RES){res.render('指数',{标题:开放式创新站'});}exports.partials =功能(REQ,RES){res.render('谐音/+ req.params.name);} 
你所不知道的前端 事件循环 浏览器渲染原理

解决方案

这已为谐音指定的路由规则不匹配的谐音文件夹例如内的任何请求子目录/谐音/文件夹/文件。路由路径匹配对待 / 作为变量之间的分隔符。因此,为了支持让您的谐音目录中的子文件,你将不得不另一条规则添加到您的应用程序,并定义一个函数来处理渲染这个模板。这如下所示:

app.js

  app.get('/谐音/:目录/:文件',routes.subpartials); 

路由/ index.js

  exports.subpartials =功能(REQ,RES){  var文件= req.params.file,      目录= req.params.directory;  res.render('谐音/+目录+/+文件);}; 

I'm working on a Node app using Express as well as Angular. I'm using Angular for routing and have my routes setup like so:

app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/', {
    templateUrl: '/partials/main'
    //controller: 'IndexController'
}).when('/discover', {
    templateUrl: '/partials/discover'
}).when('/user/home', {  //HERES THE PROBLEM CHILD!!!!!
    templateUrl: '/partials/user/home'
}).otherwise({
    redirectTo: '/'
});
}]).config(['$locationProvider', function ($locationProvider) {
    $locationProvider.html5Mode(true);
}]);

Now, whenever I try and call /user/home -- The page goes into an infinite loop and keeps reloading the controller. I can see in the node console that the page was called from partials/user/home which definitely contains a Jade file. I've checked other posts, most of them are solved with ass the / in the beginning of the partials path, that didn't help here. The page loads fine if I transfer home.jade into the /partials directory with no sub directory. Any ideas?

Update: It seems the infinite loop happens anytime I try to load a partial in any sub-directory of partials.

Per request:

Node -- App.js:

app.get('/', routes.index);

app.get('/partials/:name', routes.partials);
app.get('*', routes.index);

And routes/index.js

exports.index = function(req, res) {
res.render('index', { title: 'Open Innovation Station' });
}

exports.partials = function(req, res) {
res.render('partials/' + req.params.name);
}

解决方案

The routing rule that you have specified for partials will not match any requests to subdirectories within the partials folder e.g. /partials/folder/file. The routing path matcher treats / as a delimiter between variables. Therefore in order to support having sub folders within your partials directory you will have to add another rule to your app and define a function to handle rendering this template. This is shown below:

app.js

app.get('/partials/:directory/:file', routes.subpartials);

routes/index.js

exports.subpartials = function (req, res) {
  var file = req.params.file,
      directory = req.params.directory;
  res.render('partials/' + directory + '/' + file);
};