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.jsdevServer: { historyApiFallback: true, router.jsconst 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.vuenew Vue({ el: '#login', render: h => h(Login), store, }) 登录.vuemounted() { if (window.location.pathname === '/redirect') router.push({ path: '/redirect' }); } 请告诉我是否需要提供任何其他细节或代码。提前感谢您的帮助。
So, the problem seems to be with the top-level component
Loginacting as a traffic cop before the router boots up. I had to edit theLogincomponent to mount theRedirectcomponent manually.I don’t recommend this setting.