在不覆盖 meanjs 代码的情况下覆盖 meanjs 路由

Override meanjs routes without overwriting meanjs code

meanjs核心模块为home state提供默认索引页:

// Home state routing
$stateProvider
.state('home', {
  url: '/',
  templateUrl: 'modules/core/client/views/home.client.view.html'
})

我已将自己的模块 mymod 添加到 meanjs 应用程序中。我想使用我自己的部分 modules/mymod/client/views/browse.client.view.html.

如何在不修改 core.client.route.js 文件的情况下执行此操作?我总是避免修改从框架获得的代码,并相信重写。推荐的方法是什么?

我认为你误解了 MEANJS 的意义。来自 MEANJS github page:

MEAN.JS is a full-stack JavaScript open-source solution, which provides a solid starting point for MongoDB, Node.js, Express, and AngularJS based applications. The idea is to solve the common issues with connecting those frameworks, build a robust framework to support daily development needs, and help developers use better practices while working with popular JavaScript components.

MEANJS 不是一个严格的平台,如果你改变它自己的代码就会停止工作。当然,有些代码块不应修改,但您 can/should 修改了一些代码块,以避免随着应用程序的增长而使代码混乱。

话虽如此,您仍然可以保持原样:

$stateProvider
    .state('home', {
        url: '/',
        templateUrl: 'modules/core/client/views/home.client.view.html'
     });

并且在此部分 modules/core/client/views/home.client.view.html 中,您可以使用 AngularJS 指令 ng-include 并在 src 中放置自定义部分 browse.client.view.html 的路径。这样你就不需要修改 core.client.route.js 你只需要修改部分 modules/core/client/views/home.client.view.html.