asp.net - 如何将 Web 表单 Response.redirect 与 Angular 6 路由一起使用?
问题描述
我在 Web 表单项目的母版页中添加了一个 Angular 6 应用程序。
<app-root></app-root>
<script type="text/javascript" src="inline.bundle.js"></script>
<script type="text/javascript" src="polyfills.bundle.js"></script>
<script type="text/javascript" src="main.bundle.js"></script>
在 Web 表单母版页中,我有一个导航栏,其中包含单击以导航到其他 .aspx 页面的链接。在母版页 .cs 文件中,每个链接都有一个单击处理程序。
link.Click += navPrimary_Click;
protected void navPrimary_Click(object sender, EventArgs e)
{
Session.Add(SelectedNavItemKeyPrimary, ((LinkButton)sender).Text);
Session.Add(SelectedNavItemKeySecondary, string.Empty);
Response.Redirect(((LinkButton)sender).CommandArgument);
}
角度路线如下所示:
const routes: Routes = [{ path: 'home', component: HomeComponent }];
test.aspx 页面在浏览器中加载良好(我们称之为“ http://localhost/xyz/abc/test.aspx ”)。我可以单击导航栏中的链接,浏览器会正确加载其他 .aspx 页面。在 test.aspx 页面上,有这个角度代码:
<a routerLink="/home">Angular Home</a>
当我单击“Angular Home”链接时,角度视图显示在 test.aspx 页面上,浏览器中的 url 地址现在显示“ http://localhost/home ”而不是“ http://localhost/xyz/ ” abc/test.aspx "。
现在,当我单击任何导航栏链接时,我会得到以下信息:
“/”应用程序中的服务器错误。
无法找到该资源。
说明:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。
请求的 URL:/test.aspx
浏览器中的 url 地址现在显示“ http://localhost/test.aspx ”而不是“ http://localhost/home ”。
解决方案
推荐阅读
- postgresql - 无法根据 PostgreSQL 中另一个表中的数据过滤一个表的行
- python - Python Django 登录 URL 和视图 - 安全方法
- java - Android包含参数 - 数据绑定不解析变量
- html - 如何将一行内的 flexbox 项目居中?
- javascript - React: Cannot set property of DEBUG #Object which only has a getter
- angular - 在其他功能上使用离子存储数据
- javascript - 使用 nodejs 将表单数据插入 mysql。我哪里错了?
- authorize.net - 使用付款配置文件添加新客户时出现 Authorize.net 错误 - 代码:E00116,OTS 令牌访问违规
- linux - 当我使用 linux 跟踪事件触发器时,我无法转储堆栈跟踪
- braintree - 有什么方法可以识别 Braintree::AndroidPayCard 的 unique_number_identifier 吗?