【发布时间】:2019-06-27 19:04:36
【问题描述】:
对于单页应用,我们希望能够将所有其他未处理的请求路由到索引,以便在客户端处理路由。
以前,我们会使用 MapRoute() 添加路由,如 this answer 中详述的那样,但是,当使用 Razor 页面作为我们的索引时,这似乎不起作用。
我们如何创建 Razor Pages 索引的后备?
【问题讨论】:
标签: c# asp.net-core single-page-application razor-pages
对于单页应用,我们希望能够将所有其他未处理的请求路由到索引,以便在客户端处理路由。
以前,我们会使用 MapRoute() 添加路由,如 this answer 中详述的那样,但是,当使用 Razor 页面作为我们的索引时,这似乎不起作用。
我们如何创建 Razor Pages 索引的后备?
【问题讨论】:
标签: c# asp.net-core single-page-application razor-pages
为此,将路由添加到 Razor 页面选项,如下所示:
services.AddMvc()
.AddRazorPagesOptions(options =>
{
// Match all routes to the index so we can handle routing client-side.
options.Conventions.AddPageRoute("/index", "{*url}");
})
然后确保照常配置静态文件服务:
app.UseStaticFiles();
app.UseMvc(routes => {
routes.MapRoute(
"default",
"{controller=Home}/{action=Index}/{id?}");
});
【讨论】: