route.ts 431 B

12345678910111213141516171819
  1. import { Plugin } from '@nuxt/types'
  2. const routePlugin: Plugin = (ctx) => {
  3. if (ctx.app.router) {
  4. ctx.app.router.beforeEach((to, from, next) => {
  5. if (ctx.store.state.form.dirty) {
  6. ctx.store.commit('form/setShowConfirmToLeave', true)
  7. ctx.store.commit('form/setGoAfterLeave', to)
  8. } else {
  9. next()
  10. }
  11. })
  12. ctx.app.router.afterEach(() => {
  13. })
  14. }
  15. }
  16. export default routePlugin