vue-router icon indicating copy to clipboard operation
vue-router copied to clipboard

docs: add .net mvc example server config for history mode

Open mzhukovs opened this issue 5 years ago • 1 comments

This should be helpful for some folks from the .NET world to get routing properly setup in their [Core] MVC app. Currently, there is no sample under the server config section on this page in the docs.

mzhukovs avatar Dec 25 '18 14:12 mzhukovs

I think it would be important to differentiate in the docs between the configuration for a normal multi-page app and a SPA with REST API backend.

For example this is my configuration for an ASP.NET Core MVC REST API with a Vue SPA.

    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            // In production, the Vue files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/client-app/dist";
            });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();
            app.UseMvc();

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp/client-app";
            });
        }
    }
}

lloydjatkinson avatar Dec 27 '18 16:12 lloydjatkinson