asp.net-mvc - 从 mvc 视图重定向到角度路由 - Angular 6
问题描述
我已将我的 Angular 项目与 ASP.NET MVC 集成。我想在第一次加载时将我的 MVC 页面重定向到角度路由。我的 Index.cshtml 页面中有以下代码
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Myapp</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body class="skin-blue sidebar-mini wysihtml5-supported">
<app-root></app-root>
<script type="text/javascript" src="~/Scripts/client/runtime.js"></script>
<script type="text/javascript" src="~/Scripts/client/polyfills.js"></script>
<script type="text/javascript" src="~/Scripts/client/styles.js"></script>
<script type="text/javascript" src="~/Scripts/client/vendor.js"></script>
<script type="text/javascript" src="~/Scripts/client/main.js"></script>
</body>
</html>
我在角度索引页面中也有 index.html 页面配置。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Myapp</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root>
<div class="wrapper">
</div>
</app-root>
</body>
</html>
现在我需要将页面从这里重定向到 Angular 路径,其中登录路径是为 Angular 定义的。
{ path: 'login', component: LoginComponent },
解决方案
您拥有 Angular 从您的 cshtml 文件运行所需的一切。不需要 index.html 文件。
尝试将此添加到您的路线配置中。
{path:'', redirectTo:'login', pathMatch: 'full' }
添加此 Angular 后,默认情况下应重定向到登录路由。
推荐阅读
- angular - 使用存根测试 Angular 服务
- javascript - Axios url 获取对 html 响应的请求为 200 但 response.data 为空
- javascript - Angularjs承诺订单下载excel
- binary - 混合类型数据类型的距离函数类型是什么?
- mongodb - 使用 MongoDB 聚合创建一种“表格”投影
- c# - 意外元素
在发现 使用 Google Admob 时 - python - 理解python中的“目标”一词
- plotly.js - plotly.js 中的自定义标记符号
- javascript - Which languages do I need to build this form & database on wordpress using kinsta as host?
- r - 无法从 EDGAR 平台检索公司记录