简体   繁体   English

ASP.NET 内核 + Angular static 路由

[英]ASP.NET Core + Angular static route

I`ve created default ASP.NET Core + Angular project.我已经创建了默认的 ASP.NET 核心 + Angular 项目。 I need to open angular app only by link /angular.我只需要通过链接 /angular 打开 angular 应用程序。 Also when angular routing have to be under /angular link too, like "/angular/profile" - profile page, "/angular/item/22" - page with item.此外,当 angular 路由也必须位于 /angular 链接下时,例如“/angular/profile” - 配置文件页面,“/angular/item/22” - 包含项目的页面。 By links which don`t contains "/angular" I need open static files or MVC views.通过不包含“/angular”的链接,我需要打开 static 文件或 MVC 视图。

Default project use SPA, so I dont want to change it.默认项目使用 SPA,所以我不想更改它。

app.UseSpa(spa =>
{
    spa.Options.SourcePath = "ClientApp";

    if (env.IsDevelopment())
    {
        spa.UseAngularCliServer(npmScript: "start");
    }
});

Is there any solution for it?有什么解决办法吗?

If you want to specify the base URL to view from the Angular ClientApp folder, try to set href attribute of base by going to ClientApp > src > index.html like below:如果要从 Angular ClientApp 文件夹中指定基础 URL 以查看,请尝试通过转到ClientApp > src > index.ZFC35FDC70D5FC69D269883A822C7A53来设置basehref属性,如下所示:

<head>
 <meta charset="utf-8">
 <title>ClientApp</title>
 <base href="/angular">

 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>

After that, the URL like this:之后,URL 是这样的:

在此处输入图像描述

There is no need to change the UseSpa method, my UseSpa() method as below:无需更改 UseSpa 方法,我的 UseSpa() 方法如下:

        app.UseSpa(spa =>
        {
            // To learn more about options for serving an Angular SPA from ASP.NET Core,
            // see https://go.microsoft.com/fwlink/?linkid=864501 
            spa.Options.SourcePath = "ClientApp";

            if (env.IsDevelopment())
            {
                spa.UseAngularCliServer(npmScript: "start");
            }
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM