route.ts 376 B

12345678910111213141516
  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. }
  13. }
  14. export default routePlugin