【问题标题】:How to properly configure multiple routes in lite-server如何在 lite-server 中正确配置多条路由
【发布时间】:2016-12-08 13:53:42
【问题描述】:

我正在使用lite-server 开发一个Angular 应用程序。我的项目结构如下,很简单:

build/
    foo/
        index.html (references foo.js script)
    bar/
        index.html (references bar.js script)
foo.js
bar.js
bsconfig.json

我想做的是访问localhost:8000/foo并获取foo/index.html加载foo.js脚本以及访问localhost:8000/bar并获取bar/index.html加载bar.js。

我已阅读 Browsersync options 文档并尝试使用 routes 配置 bs-config.json 文件,但无法正常工作。

【问题讨论】:

    标签: angular browser-sync lite-server


    【解决方案1】:

    您可以设置base href 指向 index.html 文件中的不同文件夹 ,

      <base href="/foo/">
    
      <base href="/bar/">
    

    您还必须在 system.config 文件中配置您提供主包的位置。

    【讨论】:

    • 我设置了base href,但它不起作用。我认为这是lite-server 配置问题。
    【解决方案2】:

    你可以添加路由到服务器对象

    routes : {"/foo" : "build/foo", "/bar" : "build/bar" }
    

    您可以将您的 foo.js 和 bar.js 分别放在“foo”和“bar”文件夹下并在本地引用它们,或者将它们留在项目文件夹中并以“/foo.js”和“/”的形式引用bar.js"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多