Solo.vue 506 B

12345678910111213141516171819202122232425262728
  1. <template>
  2. <keep-alive :include="cacheRoutes">
  3. <router-view />
  4. </keep-alive>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'Solo',
  9. computed: {
  10. cacheRoutes () {
  11. return this.$route.meta?.cache || []
  12. }
  13. },
  14. watch: {
  15. '$route': {
  16. handler () {
  17. // solo无对应name
  18. const matched = this.$route.matched
  19. if (!matched[matched.length - 1].name) {
  20. this.$router.replace({ path: '/' })
  21. }
  22. },
  23. immediate: true
  24. }
  25. }
  26. }
  27. </script>