SO Community,
I'm trying to add external authentication to an existing Vue 2 application. The problem I'm having is that when the external IdP redirects back to the Vue application with the path /redirect
, the Vue Router doesn't seem to respect the updated path and route to the correct component. In other words, Vue Router will route to the /
component instead of the /redirect
component.
Vue Router sets mode: 'history'
and Webpack sets historyApiFallback: true,
.
https://localhost:8080/
and the Login
component is rendered. https://localhost:8080/redirect
/
, which returns the Login
component. Login
component, mounted()
hook checkif (window.location.pathname === '/redirect') router.push({ path: '/redirect' });
/
path instead of /redirect
and its components.Vue - 2.5.15
路由器视图 - 3.0.0
Webpack - 4.17.1
Webpack 开发服务器 - 3.1.4
webpack.dev.js
devServer: { historyApiFallback: true,
router.js
const router = new VueRouter({ mode: 'history', routes: [ ... { path: '/redirect', component: Redirect, }, { path: '/', redirect: () => { }, ... router.beforeEach((to, from, next) => { const user = store.state.user.authorizedUser const toPath = to.path if (toPath === '/redirect') return });
App.vue
new Vue({ el: '#login', render: h => h(Login), store, })
登录.vue
mounted() { if (window.location.pathname === '/redirect') router.push({ path: '/redirect' }); }
请告诉我是否需要提供任何其他细节或代码。提前感谢您的帮助。
So, the problem seems to be with the top-level component
Login
acting as a traffic cop before the router boots up. I had to edit theLogin
component to mount theRedirect
component manually.I don’t recommend this setting.