File tree Expand file tree Collapse file tree 3 files changed +16
-17
lines changed
Expand file tree Collapse file tree 3 files changed +16
-17
lines changed Original file line number Diff line number Diff line change 11<template >
22 <h1 >My Profile</h1 >
3- </template >
4-
5- <script >
6- import { authService } from ' ./main' ;
7-
8- export default {
9- beforeRouteEnter (to , from , next ) {
10- if (! authService .isLoggedIn ) {
11- alert (" You must be logged in!" );
12- return next (false );
13- }
14-
15- next ();
16- }
17- }
18- </script >
3+ </template >
Original file line number Diff line number Diff line change @@ -23,6 +23,17 @@ const router = new VueRouter({
2323 }
2424} ) ;
2525
26+ router . beforeEach ( ( to , from , next ) => {
27+ if ( to . matched . some ( record => record . meta . isAuthRequired ) ) {
28+ if ( ! authService . isLoggedIn ) {
29+ alert ( "You must be logged in!" ) ;
30+ return next ( false ) ;
31+ }
32+ }
33+
34+ next ( ) ;
35+ } ) ;
36+
2637Vue . filter ( 'currency' , function ( value ) {
2738 let formatter = new Intl . NumberFormat ( 'en-US' , {
2839 style : 'currency' ,
Original file line number Diff line number Diff line change @@ -18,7 +18,10 @@ export const routes = [
1818 {
1919 path : '/user/profile' ,
2020 name : 'viewProfile' ,
21- component : ViewProfile
21+ component : ViewProfile ,
22+ meta : {
23+ isAuthRequired : true
24+ }
2225 } ,
2326 { path : '/cart' , component : Cart } ,
2427 { path : '*' , component : { template : '<h1>Page Not Found!</h1>' } }
You can’t perform that action at this time.
0 commit comments