我正在用Vue重写现有的Angular 1应用程序.
该应用程序总是需要由用户进行身份验证locale,id并token进入任何意见之前.尊重API的约定,我token在主要父路由中指定了一个查询参数.
来自现有的Angular的UI路由器实现,我认为这是要走的路:
// main.js
new Vue({
el: '#app',
router,
store,
template: '<router-view name="main"></router-view>'
})
// router.js
const router = new Router({
mode: 'history',
routes: [
{
name: 'start',
path : '/:locale/:id', // /:locale/:id?token didn't work
query: {
token: null
},
beforeEnter (to, from, next) {
// 1. Get data from API via locale, id and token
// 2. Update store with user data
},
components: {
main: startComponent …Run Code Online (Sandbox Code Playgroud)