當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript vue-router.beforeEach函數代碼示例

本文整理匯總了TypeScript中vue-router.beforeEach函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript beforeEach函數的具體用法?TypeScript beforeEach怎麽用?TypeScript beforeEach使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了beforeEach函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getAllRoutes

export const createRouter = (): VueRouter => {

  const routes: IRouteConfigAugmented[] = getAllRoutes();
  const router = new VueRouter({
    mode: 'hash',
    routes,
    scrollBehavior(to, from, savedPosition) {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve({x: 0, y: 0});
        }, 400); // scroll to top for each new route
      });
    },
  });

  router.beforeEach((to, from, next) => {
    const route: IRouteConfigAugmented = _.find(routes, (rt) => rt.path === to.fullPath);
    if (route) {
      StoreW.setTitle(route.text);
      StoreW.setRoute(route);
    }

    next();
  });

  return router;
};
開發者ID:remipassmoilesel,項目名稱:personnal-website,代碼行數:27,代碼來源:router.ts

示例2: VueRouter

const createRouter = () => {
	const router = new VueRouter(ROUTER_SETTING);

	// manually hook: page not scroll to top when router changes
	// github issue: https://github.com/vuejs/vue-router/issues/173
	router.beforeEach((route, redirect, next) => {
		window.scrollTo(0, 0);
		next();
	});

	router.afterEach((route: Route) => {
		console.info(`${new Date()}: ${route.path}`);
	});

	return router;
};
開發者ID:DiscipleD,項目名稱:blog,代碼行數:16,代碼來源:router.ts

示例3: VueRouter

var router = new VueRouter();

router.map({
	'/login': {
		name: 'login',
		component: loginState,
		auth: false
	},
	'/dashboard': {
		name: 'dashboard',
		component: dashState,
		auth: true
	},
	'/transactions': {
		name: 'transactions',
		component: transState,
		auth: true
	}
});

router.beforeEach((trans:any) => {
	if (trans.to.auth && !Auth.isLogged) {
		trans.redirect('/login');
	} else {
		trans.next();
	}
});

export default router;
開發者ID:maraisr,項目名稱:gravestone,代碼行數:29,代碼來源:router.ts

示例4: mounted

        { path: '/implicit/callback', component: Auth.handleCallback() },
        {
            path: '/protected',
            component: {
                name: 'protected',
                template: '<div>Protected Route</div>'
            },
            meta: {
                requiresAuth: true
            }
        },
    ]
});

const redirectGuard = Vue.prototype.$auth.authRedirectGuard();
router.beforeEach(redirectGuard);

const component = Vue.extend({
    mounted() {
        const authd = this.$auth.isAuthenticated();
        const userInfo = this.$auth.getUser();
        const handleAuth = this.$auth.handleAuthentication();
        const path = this.$auth.getFromUri();
        const idToken = this.$auth.getIdToken();
        const accessToken = this.$auth.getAccessToken();
    },
    methods: {
        logout() {
            const logoutPromise = this.$auth.logout();
        },
        redirect() {
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:okta__okta-vue-tests.ts

示例5: if

})

router.beforeEach((to, from, next) => {
	if (to.matched.some((record) => record.meta.authorizedZone)) {
		if (!storage.getItem(config.tokenName)) {
			// console.log('Checkpoint #1')
			next({
				path: '/login',
				// query: { redirect: to.fullPath }
			})
		} else {
			// console.log('Checkpoint #2')
			next()
		}
	} else if (to.matched.some((record) => record.meta.loginPage)) {
		if (storage.getItem(config.tokenName)) {
			// console.log('Checkpoint #3')
			next({
				path: '/',
				// query: { redirect: to.fullPath }
			})
		} else {
			// console.log('Checkpoint #4')
			next()
		}
	} else {
		// console.log('Checkpoint #5')
		next() // make sure to always call next()!
	}
})

export default router
開發者ID:InnoDevelopment,項目名稱:frontend,代碼行數:32,代碼來源:router.ts


注:本文中的vue-router.beforeEach函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。