router.ts 785 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Vue Router support
  3. */
  4. import { RenderContext } from 'vue/types';
  5. import VueRouter, { RawLocation } from 'vue-router/types';
  6. export type RouteConfig = {
  7. url?: string;
  8. to?: RawLocation;
  9. replace?: boolean;
  10. };
  11. export function route(router: VueRouter, config: RouteConfig) {
  12. const { to, url, replace } = config;
  13. if (to && router) {
  14. router[replace ? 'replace' : 'push'](to);
  15. } else if (url) {
  16. replace ? location.replace(url) : (location.href = url);
  17. }
  18. }
  19. export function functionalRoute(context: RenderContext) {
  20. route(context.parent && context.parent.$router, context.props);
  21. }
  22. export type RouteProps = {
  23. url?: string,
  24. replace?: boolean;
  25. to?: RawLocation;
  26. }
  27. export const routeProps = {
  28. url: String,
  29. replace: Boolean,
  30. to: [String, Object]
  31. };