router.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.route = route;
  4. exports.functionalRoute = functionalRoute;
  5. exports.routeProps = void 0;
  6. /**
  7. * Vue Router support
  8. */
  9. function isRedundantNavigation(err) {
  10. return err.name === 'NavigationDuplicated' || // compatible with vue-router@3.3
  11. err.message && err.message.indexOf('redundant navigation') !== -1;
  12. }
  13. function route(router, config) {
  14. var to = config.to,
  15. url = config.url,
  16. replace = config.replace;
  17. if (to && router) {
  18. var promise = router[replace ? 'replace' : 'push'](to);
  19. /* istanbul ignore else */
  20. if (promise && promise.catch) {
  21. promise.catch(function (err) {
  22. if (err && !isRedundantNavigation(err)) {
  23. throw err;
  24. }
  25. });
  26. }
  27. } else if (url) {
  28. replace ? location.replace(url) : location.href = url;
  29. }
  30. }
  31. function functionalRoute(context) {
  32. route(context.parent && context.parent.$router, context.props);
  33. }
  34. var routeProps = {
  35. url: String,
  36. replace: Boolean,
  37. to: [String, Object]
  38. };
  39. exports.routeProps = routeProps;