【问题标题】:Angular Routing Changing the Root of the original request URL baseAngular Routing 改变原始请求 URL base 的根
【发布时间】:2022-11-22 04:33:35
【问题描述】:

我有一个使用路由的角度应用程序。

它的默认页面 (index.html) 位于 /somefolder/index.html

我需要应用程序的其余部分 /someotherfolder/ ...所有脚本和资源

我可以让它与 deploy-url 一起工作,修改 base ref 等。

所以导航到

http://someip/somefolder/

有效,但 angular 将 url 更改为

http://someip/someotherfolder/#/route where route is one of my routes.

有没有办法保留原来的基地? IE

http://someip/somefolder/#/route

我尝试过的一切都没有成功。另外是的,由于超出了这个问题范围的限制,他们必须住在服务器的不同区域。非常感谢任何想法或建议。

【问题讨论】:

    标签: angular angular-routing


    【解决方案1】:

    正如this 回答中提到的,您可以在您的应用程序模块中提供APP_BASE_HREF 以更改路由器使用的基本 URL。

    在你的例子中,URL 不是动态的,所以如果你有一个环境文件,你可以在那里设置基本 URL 并像这样提供它:

    // Inside @NgModule in AppModule...
    providers: [
      // Other providers...
      {
        provide: APP_BASE_HREF,
        useValue: environment.appBaseUrl
      },
    ]
    

    【讨论】:

      猜你喜欢
      • 2021-02-14
      • 1970-01-01
      • 2013-01-24
      • 2017-06-01
      • 2020-11-29
      • 2010-11-04
      • 2019-09-21
      • 2012-02-15
      • 1970-01-01
      相关资源
      最近更新 更多