【问题标题】:ASP MVC Areas and Angular Lazy Loading pathsASP MVC 区域和角度延迟加载路径
【发布时间】:2019-02-22 09:09:23
【问题描述】:

我有这个工作,但不优雅

(1) 角度

这会将它的输出放在文件夹中

~/Areas/AreaName/Views/ControllerName/ClientApp/(all angular files here)

它有类似的路径

<button class="k-button" routerLink="AreaName/ControllerName/LazyLoad">LazyLoad</button>&nbsp;
<button class="k-button" [routerLink]="['AreaName/ControllerName/Home']">Home</button>&nbsp;

延迟加载的路由是这样的

{
    path: 'AreaName/ControllerName/LazyLoad',
    loadChildren: './lazyLoad/lazyLoad.module#LazyLoadedModule'
}

(2)MVC

在 AreaRegistration 中,我有 Angular 代码的附加路径

        context.MapRoute(
            "Angular",
            "AreaName/ControllerName/{*.}",
            new { controller = "ControllerName", action = "Index", id = UrlParameter.Optional }); 

它运行正常,当它尝试加载延迟加载部分时,它会在路径中查找

/AreaName/lazyLoad-lazyLoad-module.js

如果它查看“/”或“AreaName/ControllerName”或类似但不是该路径的内容,我可以理解

为了完成这项工作,我在 Global.ascx.cs Application_Error 中有代码,它检测到 404 并将其重定向到正确的路径,即

~/Areas/AreaName/Views/ControllerName/ClientApp/

然后工作,它会加载延迟加载的文件

我假设我需要在 Angular 方面做一些事情,但我不确定是什么?

NB 这不是 ASP MVC 的核心版本

编辑,更多信息) 我在 Angular.json 中找到了 deployUrl。不幸的是,我们的网站可以通过以下任何方式托管:

https://OurSite/TopLevel
https://OurSite/_FurtherDown/TopLevel

href 将在 index.html 中设置,也许 deployUrl 有一个等价物?

【问题讨论】:

    标签: angular asp.net-mvc-areas


    【解决方案1】:

    这或多或少是

    的复制品

    Changing Angular 5 publish url at runtime

    但特定于 ASP MVC 领域,所以我就让它站起来

    我已经从 Global.ascx 中删除了 404 代码

    在 Index.cshtml 文件中我添加了这个

    window.DeployUrlFromMyProduct = "@(Request.ApplicationPath)/Areas/MyArea/Views/ControllerName/Ang/";
    

    而在 app.module.ts 中,

    declare var __webpack_public_path__: any;
    __webpack_public_path__ = (<any>window).DeployUrlFromKiosk;
    

    我知道另一个问题说 public var webpack_public_path 不起作用,但对我来说似乎是

    到目前为止的最小测试,任何问题,我都会将它们添加为评论

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-12
      • 1970-01-01
      • 2017-12-05
      相关资源
      最近更新 更多