1

I have two applications running at the same time, the first is the new implementation in Angular 7 + asp core, the second is a legacy application in asp mvc 5 (no Angular app, that HTML does not implement any Angular code), the problem is that we want to slowly get rid of the legacy app. For this we have decided to call certain controllers (mvc5) renderer for the legacy application in the server, so the call to /legacy/menu returns an html with the menu of the legacy application.

How can I elegantly trick an Angular 7 component, so that when I call a RouterModule they return the /legacy/menu html? I understand that it's not the Angular concept but what we want to have two components "one for the new app" and the other one" for the legacy version", while we are implementing the new version, have the step component of the old version. All of this is a provisional idea to make the transition.

1 Answer 1

1

You should just create a new angular project template and see how they do it there. There's have a nicer convenience method. Or you can set up static file serving using StaticFiles

public void Configure(IApplicationBuilder app)
{
    app.UseStaticFiles(); // For the wwwroot folder

    app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images")),
        RequestPath = "/MyImages"
    });

    app.UseDirectoryBrowser(new DirectoryBrowserOptions
    {
        FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images")),
        RequestPath = "/MyImages"
    });
}  

For Mor information checkout the Microsoft help page for serving static files

You can get more granular control using the built in methods for SPA

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

    spa.UseSpaPrerendering(options =>
    {
        options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.bundle.js";
        options.BootModuleBuilder = env.IsDevelopment()
            ? new AngularCliBuilder(npmScript: "build:ssr")
            : null;
        options.ExcludeUrls = new[] { "/sockjs-node" };
    });

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

Here is the microsoft reference

Sign up to request clarification or add additional context in comments.

4 Comments

Hi @johnny 5 "/legacy/menu" is a Controller action call. But how can I trick Angular component just call httpClient.get?
@gvivetapl that is ambigious, Do you mean and ASP.Net Controller Action, Or an Angular Controller Action, It would be a lot easier to solve if you posted your existing code or example code which depicts the issue in a clear way
I mean that I have ASP.Net Controller Action with html result which I want to retrieve html in my Angular 7 client side that HTML does not implement any Angular code.
@gvivetapi, let me attempt to clarify, because what you said in your comment and question are different, are you trying to serve html from a .net core controller which will map to a route in your angular application?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.