router.js 907 B

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