【问题标题】:Make 2 modules in 1 project在 1 个项目中制作 2 个模块
【发布时间】:2018-01-02 03:32:10
【问题描述】:

我有一个mean-stack 项目。在我的index.js,我到底有没有

router.get('*', function(req, res) {
    res.sendfile('./views/index.html');
})
module.exports = router;

现在我想通过./views/addinIndex.html 处理与https://localhost:3000/1/addin/* 匹配的所有网页,我希望在其中引用不同的外部文件并定义不同的模块。因此,我添加了另一个router.get

router.get('/1/addin/*', function (req, res) {
    res.sendfile('./views/addinIndex.html')
})
router.get('*', function(req, res) {
    res.sendfile('./views/index.html');
})
module.exports = router;

这里是addinIndex.html

<html>
<head>
    <script src="https://code.jquery.com/jquery.min.js"></script>
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.2/angular-ui-router.js"></script>
    <script> 
        jQuery(document).ready(function () {
            angular.bootstrap(document, ['app']);
            console.log("bootstrapped")
        })
        app = angular.module('app', ['ui.router'])
        app.config(['$stateProvider', function($stateProvider) {
            $stateProvider
                .state('addinHome1', {
                    url: '/1/addin/home',
                    template: 'addinHome1'
                })
                .state('addinHome2', {
                    url: '/addin/home',
                    template: 'addinHome2'
                })
                .state('addinHome3', {
                    url: '/home',
                    template: 'addinHome3'
                })
        }])
    </script>
</head>
<body>
    abcde
    <ui-view ng-cloak></ui-view>
</body>
</html>

但是,当我运行https://localhost:3000/1/addin/home 时,它只显示abcde 而没有其他任何内容,而bootstrapped 打印在控制台中。

有谁知道怎么回事?我可以像这样定义一个额外的addinIndex.html,因为我已经有一个工作的index.html

【问题讨论】:

    标签: javascript angularjs express angular-ui-router mean-stack


    【解决方案1】:

    是的,可以根据路线提供不同的索引。 但为此,您必须从 url 中删除 #

    要做到这一点,请按照以下步骤操作。

    1. 我们将使用 $locationProvider 模块并将 html5Mode 设置为 true。

      // use the HTML5 History API
      $locationProvider.html5Mode(true);
      
    2. 要使用相对链接链接您的应用程序,您需要在文档中设置 a。在您的角度配置中添加以下代码。

      <base href="/">
      

    【讨论】:

    • 谢谢...不知道是不是和html5mode有关,以后试试你的解决方案...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 2019-04-28
    • 1970-01-01
    • 2015-11-03
    相关资源
    最近更新 更多