route.ts 466 B

1234567891011121314151617181920
  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. ctx.store.commit('form/setDirty', false)
  14. })
  15. }
  16. }
  17. export default routePlugin