[英]Angular 2 setup issue with asp.net core while using controller name and action name main.js not found
I have successfully setup my angular 2 application in asp.net core which is working great. 我已经在asp.net核心中成功设置了我的angular 2应用程序,该应用程序运行良好。 My main.js file is inside the app folder . 我的main.js文件位于app文件夹中 。
Working fine beacause the default mvc templete is 工作正常,因为默认的MVC Templete是
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
I am facing a new problem. 我正面临一个新问题。 I have use the achor tag as below. 我使用了如下的achor标签。 ` `
<li><a asp-controller="Account" asp-action="Login">Login </a></li>
Now the navigation URL is http://localhost:28739/Account/Login 现在导航URL为http:// localhost:28739 / Account / Login
In my systemjs.config.js I have mention the main as show below 在我的systemjs.config.js中,我提到了主要内容,如下所示
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'angular2-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
}
Its works great when there is no controller name and action name in the url. 当URL中没有控制器名称和动作名称时,它的效果很好。 But when their is controller name and action name. 但是当它们是控制器名称和动作名称时。 It gives me a error as main.js not found. 由于找不到main.js,这给了我一个错误。 Below is the image. 下面是图像。
Can anyone please tell me how to solve this issue. 谁能告诉我如何解决这个问题。
Finally Found the solution. 终于找到了解决方案。 Here is the reference link http://blog.nbellocam.me/2016/03/21/routing-angular-2-asp-net-core/ 这是参考链接http://blog.nbellocam.me/2016/03/21/routing-angular-2-asp-net-core/
I have added in startup.cs 我在startup.cs中添加了
routes.MapRoute(
name: "spa-fallback",
template: "{*url}",defaults: new { controller = "Home", action = "Index" });
And add <Head><base href="/" /></Head>
in the layout view 并在布局视图中添加<Head><base href="/" /></Head>
在索引页面中使用<base href="/" />
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.