billy jean
billy jean

Reputation: 1419

Set route from MVC and Internal Vue.js Spa to webroot, hide controller name from URL

I am trying to route a controller/action which returns my Vue.js application to the webroot so the URL hides the controller name.

my current routes:

app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=MySpaController}/{action=Index}/{id?}");
            routes.MapSpaFallbackRoute(
               name: "spa-fallback",
               defaults: new { controller = "MySpaController", action = "Index" });
        });

Navigating to http://localhost/ routes to the correct root/home action and the vue.js spa application is returned. But the URL in the browser changes to http://localhost/MySpaController . If I attempt to navigate to any routes within the app without the MySpaController portion the request is externally routed and the http://localhost/MySpaController/Index action is called again.

I would like to hide the controller name from the url.

Upvotes: 0

Views: 1154

Answers (1)

billy jean
billy jean

Reputation: 1419

in Vue Router ensure base is set to '/' like:

let router = new VueRouter({
  base: '/',
  mode: 'history',
  linkActiveClass: "active",
  routes
})

Upvotes: 0

Related Questions