Skip to content

Commit 20a68f2

Browse files
committed
Add navigation guards question
1 parent e2a7afd commit 20a68f2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ List of 300 VueJS Interview Questions
227227
|218| [What is the purpose of comments option?](#what-is-the-purpose-of-comments-option)|
228228
|219| [How to identify whether code is running on client or server?](#how-to-identify-whether-code-is-running-on-client-or-server)|
229229
|220| [How do you watch route object changes?](#how-do-you-watch-route-object-changes)|
230+
|221| [How do you sync current route in vuex store?](#how-do-you-sync-current-route-in-vuex-store)|
231+
|222| [What are navigation guards in vue router?](#what-are-navigation-guards-in-vue-router)|
230232

231233
1. ### What is VueJS?
232234
**Vue.js** is an open-source, progressive Javascript framework for building user interfaces that aim to be incrementally adoptable. The core library of VueJS is focused on the `view layer` only, and is easy to pick up and integrate with other libraries or existing projects.
@@ -3984,3 +3986,23 @@ List of 300 VueJS Interview Questions
39843986
}
39853987
}
39863988
```
3989+
221. ### How do you sync current route in vuex store?
3990+
You can use `vue-router-sync` library to sync current $route object in vuex store's state. The usage is quite straight forward with two steps
3991+
1. **Installation:**
3992+
```bash
3993+
npm install vuex-router-sync
3994+
```
3995+
2. **Sync router and store:**
3996+
```javascript
3997+
import { sync } from 'vuex-router-sync'
3998+
import store from './vuex/store' // vuex store instance
3999+
import router from './router' // vue-router instance
4000+
4001+
const unsync = sync(store, router) // Returns an unsync callback function
4002+
unsync() // Unsyncs store from router
4003+
```
4004+
222. ### What are navigation guards in vue router?
4005+
The navigation guards of vue-router are used to protect navigations either by redirecting it or canceling it. Below are the 3 different ways to hook into router navigations
4006+
1. Global:
4007+
2. Per-route:
4008+
3. In-component:

0 commit comments

Comments
 (0)