asp.net-mvc - How to handle multiple VueJS SPAs application in ASP.NET Core 3
问题描述
I have an ASP.NET Core Web API application, I want to serve two VueJS apps, one for Admin and one for Users.
So I did the setup configuration like this:
app.Map("/users",
adminApp =>
{
adminApp.UseSpa(spa =>
{
spa.Options.SourcePath = "AppFront";
spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "AppFront"))
};
spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
spa.UseVueCli(npmScript: "serve", port: 4200);
});
}
);
app.Map("/admin",
adminApp =>
{
adminApp.UseSpa(spa =>
{
spa.Options.SourcePath = "AppAdmin";
spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "AppAdmin"))
};
spa.UseProxyToSpaDevelopmentServer("http://localhost:4201");
spa.UseVueCli(npmScript: "serve", port: 4201);
});
}
);
Here is the project structure:
The problem is, when I tried to access the admin page, for example: It is not loading the script correctly.
I found that the problem is because I'm not adding the prefix "admin" to VueJS Javascript path.
How can I add this prefix? Is it possible?
Regards
解决方案
因为您的 vue 基础 url 不是“/”,所以您需要在每个 vuejs 项目根目录的 vue.config.js 中设置publicPath
// ./AppAdmin/vue.config.js
module.exports = {
publicPath: '/admin'
}
// ./AppFront/vue.config.js
module.exports = {
publicPath: '/users'
}
推荐阅读
- cakephp - 了解 Cake PHP 路由
- c# - 存储库仅在某些情况下获取数据
- sql - 数据挑战 - postgres sql - 对时间跟踪事件进行编号
- php - 在 php 中获取 Name 值以及如何使用 post 获取它
- json - 在Angular中以特定格式分离和排列数据?
- javascript - 在 Vue JS 中,从 vue 实例中的方法调用过滤器,但 $options 未定义
- c++ - 如何声明和定义推导类型的静态成员?
- docker - Ping:使用超级账本结构图像时找不到命令
- r - 在R中将一行数据帧转换为向量
- javascript - 无法将 nest.js 项目部署到 Google Firebase 函数