I found a solution for this:
We can easily use any sample vue app created with the vue-cli. Because this is really a matter of serving static files via a HTTP server, which would work in .NET MVC.
Create your vue app anywhere within your project. Personally I would advise you to create it at the root level of your .net mvc project.
Add a vue.config.js file and specify the publicPath which will determine where the path of the folder where all static files will be generated.
Add a controller to serve the static files that will be created by the vue app.
For best practices, make sure that the name of your controller has the same name as the name of the folder specified in the publicPath.
Example:
vue.config.js
module.export = {
publicPath:'~/Dist'
}
public class DistController : Controller {
}
- ONLY APPLICABLE IF YOU HAVE VUE ROUTER IN YOUR APP:
For every route you defined in vue-router, make sure you have an Action method of the same name as the path of that route. Each method needs to return the static html or cshtml file that was generated.
NOTE: for your main component, make sure you use a custom path name ie (not using '/')
Example:
const router = new VueRouter({
routes: [
{ path: '/home', component: Home },
{ path: '/login', component: Login },
{ path: '/about', component: About }
]
})
public class DistController : Controller {
public ActionResult home()
{
return new FilePathResult("~/Html/index.html", "text/html");
}
public ActionResult about()
{
return new FilePathResult("~/Html/index.html", "text/html");
}
public ActionResult login()
{
return new FilePathResult("~/Html/index.html", "text/html");
}
- build your project for production:
At the time of this comment, you can use the following command to do this:
npm run build
The folder with all the static files will be generated.