Frontend是Express提供的Angular6 SPA。 Express与password.js一起用于根据身份验证提供程序进行身份验证。
Passport.js效果很好-令牌交换等效果很好。 我的问题似乎出在路由中:
由我的Angular SPA的authenticationGuard提供的login.html页面包含一个<a href="localhost:4040/auth/provider">Login with provider</a>
在快递方面,我有一个
router.get('/auth/provider', passport.authenticate('myStrategy'));
和一个
router.get('/auth/provider/callback',
passport.authenticate('myStrategy', { failureRedirect: '../../../' }),
function(req, res) {
res.send('authenticated');
}
);
我希望登录链接可以将我发送到/auth/provider
快速路由,该路由应由express捕获,然后用passport.js处理。
但是,该路由被有角路由器捕获,该路由器无法识别该路由,并将我重定向到login.html页面。
我在这里看到了一些在链接定义中使用target="_self"
的解决方案,但是这些解决方案似乎不适用于html5样式路由,仅适用于哈希爆炸路由。
“设置window.location='IP:port/auth/provider'
”的解决方案也不起作用-也会重定向到登录。
实际上,我的问题是:如何从使用html5样式路由的angular6 SPA内触发快速路由?
app-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
// Fallback when no prior route is matched
// { path: '**', redirectTo: '', pathMatch: 'full' }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule {}