All the examples of using AngularJs with MVC6/vNext/.NET5 all use a static index.html file that is within the wwwroot. Done that, but i now need to load an MVC index.cshtml page instead so i can inject settings that are in my config.json onto the page.
All i want is a default page (Home), that is loaded not matter what url is requested, provided that url is not to a js/css file or to an api controller.
I have tried adding this to my Configure(IApplicationBuilder app, IServiceProvider serviceProvider) method, but now, my js and css files all pull back the Home/Index.cshtml file
app.UseMvc(options =>
{
options.MapRoute("Api",
template: "api/{version}/{controller}/{action?}",
defaults: new { version = "v1", controller = "Page" });
options.MapRoute(
name: "default",
template: "{*url}",
defaults: new { controller = "Home", action = "Index" });
});
My application loads up on the default address http://localhost:port, there is no extra folder to start with. Via angularJs, users can go to urls such as
http://localhost:6000/page
http://localhost:6000/page/9
http://localhost:6000/another
http://localhost:6000/another/9/sub
All these should load the Home/Index.cshtml page, and let angular take over routing.
I have seen an option to add something to web.config file, but i will not be using IIS so this is not an option
EDIT If i update my routes to this, it seem to load the page and all js/css files, which is great. But if i try to go directly to a angular route, nothing loads.
app.UseMvc(options =>
{
options.MapRoute("Api",
template: "api/{version}/{controller}/{action?}",
defaults: new { version = "v1", controller = "Page" });
options.MapRoute(
name: "default",
template: "{controller}/{action?}",
defaults: new { controller = "Home", action = "Index" });
});
EDIT 2
public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider)
{
// add automapper registrations
app.RegisterMappingFiles();
// Enable all static file middleware
app.UseStaticFiles();
// Enable Mvc for controllers
app.UseMvc(options =>
{
options.MapRoute(
name: "default",
template: "{controller}/{action?}",
defaults: new { controller = "Home", action = "Index" });
});
}