每个客户端路由都以哈希开头。如何在 Vue Router 中启用历史记录模式而不干扰 api 路由?
此外,我不想以“/api”开始我的路线。客户端路由不适用于 Config.HandlerFactoryPath 设置为“api”的情况。有办法实现吗?
APPHOST
public class AppHost : AppHostBase
{
private BackendSettings _settings;
private IHostingEnvironment _environment;
public AppHost(BackendSettings settings, IHostingEnvironment environment) : base("Template.Www", typeof(SurveyService).Assembly)
{
_settings = settings;
_environment = environment;
Routes
.Add<GetSurvey>("/api/survey/{id}", "GET");
}
public override void Configure(Container container)
{
bool isDevelopment = _environment.IsDevelopment();
Plugins.Add(new TemplatePagesFeature());
SetConfig(new HostConfig
{
AddRedirectParamsToQueryString = true,
DebugMode = isDevelopment,
});
}
}
启动
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration) => Configuration = configuration;
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var backendSettings = GetBackendSettings();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseServiceStack(new AppHost(backendSettings, env));
}
private BackendSettings GetBackendSettings()
{
var settings = new BackendSettings();
Configuration.GetSection("Backend").Bind(settings);
return settings;
}
private FrontendSettings GetFrontendSettings()
{
var settings = new FrontendSettings();
Configuration.GetSection("Frontend").Bind(settings);
return settings;
}
}
请求模型
[Exclude(Feature.Metadata)]
[FallbackRoute("/{PathInfo}", Matches = "AcceptsHtml")]
public class Fallback
{
public string PathInfo { get; set; }
}
VUE路由器
export default new Router({
mode: 'history',
routes: [
{
path: '/',
component: Home
},
{
path: '/test',
component: Test
},
{
path: '*',
redirect: '/'
}
]
})
最佳答案
[FallbackRoute]
的目的是在不匹配的路由上返回主页,因此如果该路由仅在客户端上定义,则全页请求将返回主页,以便客户端路由可以处理路由。
不可能有匹配的服务器路由和客户端路由,因为客户端路由需要服务器上的回退处理程序来返回主页,而这仅在不匹配的请求上发生。
关于vuejs2 - 具有 ServiceStack 路由回退和 Api 前缀的 Vue.js 路由器历史记录模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52096652/