use-route.mjs 480 B

1234567891011121314151617181920212223242526272829
  1. import {
  2. getCurrentInstance
  3. } from "vue";
  4. const routeProps = {
  5. to: [String, Object],
  6. url: String,
  7. replace: Boolean
  8. };
  9. function route({
  10. to,
  11. url,
  12. replace,
  13. $router: router
  14. }) {
  15. if (to && router) {
  16. router[replace ? "replace" : "push"](to);
  17. } else if (url) {
  18. replace ? location.replace(url) : location.href = url;
  19. }
  20. }
  21. function useRoute() {
  22. const vm = getCurrentInstance().proxy;
  23. return () => route(vm);
  24. }
  25. export {
  26. route,
  27. routeProps,
  28. useRoute
  29. };