New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Add ASP .NET MVC Server Setup for Routes #2551

Closed
mzhukovs opened this Issue Dec 24, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@mzhukovs
Copy link

mzhukovs commented Dec 24, 2018

What problem does this feature solve?

In the docs on this page: https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
There is no example for an ASP .NET MVC app, which I am sure some folks would find helpful.

What does the proposed API look like?

Add this sample C# code for ASP .NET MVC:

Startup.cs:

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
         ...

            // Standard Server-side Route to load our SPA
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            // Here, we make sure that if url is for an API call we would still get an actual 404 response if not found, otherwise for the SPA, we are set up to handle them using a component page
            app.MapWhen(x => !x.Request.Path.Value.StartsWith("/api"), builder =>
            {
                builder.UseMvc(routes =>
                {
                    routes.MapSpaFallbackRoute(
                        name: "spa-fallback",
                        defaults: new { controller = "Home", action = "Index" });
                });
            });
        }
@posva

This comment has been minimized.

Copy link
Member

posva commented Dec 24, 2018

Sure, feel free to create a PR for it, I will ask for others ASP devs reviews 😀
Closing as I cannot add docs for every single existing server out there

@posva posva closed this Dec 24, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment