@merkur/plugin-router 0.36.0 → 0.36.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.cjs CHANGED
@@ -19,6 +19,7 @@ function createRouter(widget, routes, options) {
19
19
  widget.$dependencies.link = generateUrls(widget.$dependencies.router, {
20
20
  stringifyQueryParams: (params) => new URLSearchParams(params).toString(),
21
21
  });
22
+ widget.$in.router.options = options;
22
23
  }
23
24
 
24
25
  function routerPlugin() {
@@ -28,6 +29,7 @@ function routerPlugin() {
28
29
 
29
30
  widget.$in.router = {
30
31
  route: null,
32
+ options: {},
31
33
  pathname: null,
32
34
  isMounting: false,
33
35
  isRouteActivated: false,
@@ -69,6 +71,20 @@ function routerPlugin() {
69
71
  };
70
72
  }
71
73
 
74
+ function getOrigin(widget) {
75
+ const { protocol, host } = widget.$in.router.options;
76
+
77
+ if (!host) {
78
+ return '';
79
+ }
80
+
81
+ if (!protocol) {
82
+ return `//${host}`;
83
+ }
84
+
85
+ return `${protocol.replace(':', '').trim()}://${host.trim()}`;
86
+ }
87
+
72
88
  function routerAPI() {
73
89
  return {
74
90
  router: {
@@ -76,7 +92,14 @@ function routerAPI() {
76
92
  widget.emit(RouterEvents.REDIRECT, { url, ...data });
77
93
  },
78
94
  link(widget, routeName, data = {}) {
79
- return widget.$dependencies.link(routeName, data);
95
+ const origin = getOrigin(widget);
96
+ const path = widget.$dependencies.link(routeName, data);
97
+
98
+ if (origin && path === '/') {
99
+ return origin;
100
+ }
101
+
102
+ return `${origin}${path}`;
80
103
  },
81
104
  getCurrentRoute(widget) {
82
105
  return widget.$in.router.route;
package/lib/index.es9.cjs CHANGED
@@ -13,6 +13,7 @@ function createRouter(widget, routes, options) {
13
13
  widget.$dependencies.link = generateUrls(widget.$dependencies.router, {
14
14
  stringifyQueryParams: params => new URLSearchParams(params).toString()
15
15
  });
16
+ widget.$in.router.options = options;
16
17
  }
17
18
  function routerPlugin() {
18
19
  return {
@@ -20,6 +21,7 @@ function routerPlugin() {
20
21
  core.assignMissingKeys(widget, routerAPI());
21
22
  widget.$in.router = {
22
23
  route: null,
24
+ options: {},
23
25
  pathname: null,
24
26
  isMounting: false,
25
27
  isRouteActivated: false,
@@ -47,6 +49,19 @@ function routerPlugin() {
47
49
  }
48
50
  };
49
51
  }
52
+ function getOrigin(widget) {
53
+ const {
54
+ protocol,
55
+ host
56
+ } = widget.$in.router.options;
57
+ if (!host) {
58
+ return '';
59
+ }
60
+ if (!protocol) {
61
+ return `//${host}`;
62
+ }
63
+ return `${protocol.replace(':', '').trim()}://${host.trim()}`;
64
+ }
50
65
  function routerAPI() {
51
66
  return {
52
67
  router: {
@@ -57,7 +72,12 @@ function routerAPI() {
57
72
  });
58
73
  },
59
74
  link(widget, routeName, data = {}) {
60
- return widget.$dependencies.link(routeName, data);
75
+ const origin = getOrigin(widget);
76
+ const path = widget.$dependencies.link(routeName, data);
77
+ if (origin && path === '/') {
78
+ return origin;
79
+ }
80
+ return `${origin}${path}`;
61
81
  },
62
82
  getCurrentRoute(widget) {
63
83
  return widget.$in.router.route;
package/lib/index.es9.mjs CHANGED
@@ -11,6 +11,7 @@ function createRouter(widget, routes, options) {
11
11
  widget.$dependencies.link = generateUrls(widget.$dependencies.router, {
12
12
  stringifyQueryParams: params => new URLSearchParams(params).toString()
13
13
  });
14
+ widget.$in.router.options = options;
14
15
  }
15
16
  function routerPlugin() {
16
17
  return {
@@ -18,6 +19,7 @@ function routerPlugin() {
18
19
  assignMissingKeys(widget, routerAPI());
19
20
  widget.$in.router = {
20
21
  route: null,
22
+ options: {},
21
23
  pathname: null,
22
24
  isMounting: false,
23
25
  isRouteActivated: false,
@@ -45,6 +47,19 @@ function routerPlugin() {
45
47
  }
46
48
  };
47
49
  }
50
+ function getOrigin(widget) {
51
+ const {
52
+ protocol,
53
+ host
54
+ } = widget.$in.router.options;
55
+ if (!host) {
56
+ return '';
57
+ }
58
+ if (!protocol) {
59
+ return `//${host}`;
60
+ }
61
+ return `${protocol.replace(':', '').trim()}://${host.trim()}`;
62
+ }
48
63
  function routerAPI() {
49
64
  return {
50
65
  router: {
@@ -55,7 +70,12 @@ function routerAPI() {
55
70
  });
56
71
  },
57
72
  link(widget, routeName, data = {}) {
58
- return widget.$dependencies.link(routeName, data);
73
+ const origin = getOrigin(widget);
74
+ const path = widget.$dependencies.link(routeName, data);
75
+ if (origin && path === '/') {
76
+ return origin;
77
+ }
78
+ return `${origin}${path}`;
59
79
  },
60
80
  getCurrentRoute(widget) {
61
81
  return widget.$in.router.route;
package/lib/index.js CHANGED
@@ -19,6 +19,7 @@ function createRouter(widget, routes, options) {
19
19
  widget.$dependencies.link = generateUrls(widget.$dependencies.router, {
20
20
  stringifyQueryParams: (params) => new URLSearchParams(params).toString(),
21
21
  });
22
+ widget.$in.router.options = options;
22
23
  }
23
24
 
24
25
  function routerPlugin() {
@@ -28,6 +29,7 @@ function routerPlugin() {
28
29
 
29
30
  widget.$in.router = {
30
31
  route: null,
32
+ options: {},
31
33
  pathname: null,
32
34
  isMounting: false,
33
35
  isRouteActivated: false,
@@ -69,6 +71,20 @@ function routerPlugin() {
69
71
  };
70
72
  }
71
73
 
74
+ function getOrigin(widget) {
75
+ const { protocol, host } = widget.$in.router.options;
76
+
77
+ if (!host) {
78
+ return '';
79
+ }
80
+
81
+ if (!protocol) {
82
+ return `//${host}`;
83
+ }
84
+
85
+ return `${protocol.replace(':', '').trim()}://${host.trim()}`;
86
+ }
87
+
72
88
  function routerAPI() {
73
89
  return {
74
90
  router: {
@@ -76,7 +92,14 @@ function routerAPI() {
76
92
  widget.emit(RouterEvents.REDIRECT, { url, ...data });
77
93
  },
78
94
  link(widget, routeName, data = {}) {
79
- return widget.$dependencies.link(routeName, data);
95
+ const origin = getOrigin(widget);
96
+ const path = widget.$dependencies.link(routeName, data);
97
+
98
+ if (origin && path === '/') {
99
+ return origin;
100
+ }
101
+
102
+ return `${origin}${path}`;
80
103
  },
81
104
  getCurrentRoute(widget) {
82
105
  return widget.$in.router.route;
package/lib/index.mjs CHANGED
@@ -17,6 +17,7 @@ function createRouter(widget, routes, options) {
17
17
  widget.$dependencies.link = generateUrls(widget.$dependencies.router, {
18
18
  stringifyQueryParams: (params) => new URLSearchParams(params).toString(),
19
19
  });
20
+ widget.$in.router.options = options;
20
21
  }
21
22
 
22
23
  function routerPlugin() {
@@ -26,6 +27,7 @@ function routerPlugin() {
26
27
 
27
28
  widget.$in.router = {
28
29
  route: null,
30
+ options: {},
29
31
  pathname: null,
30
32
  isMounting: false,
31
33
  isRouteActivated: false,
@@ -67,6 +69,20 @@ function routerPlugin() {
67
69
  };
68
70
  }
69
71
 
72
+ function getOrigin(widget) {
73
+ const { protocol, host } = widget.$in.router.options;
74
+
75
+ if (!host) {
76
+ return '';
77
+ }
78
+
79
+ if (!protocol) {
80
+ return `//${host}`;
81
+ }
82
+
83
+ return `${protocol.replace(':', '').trim()}://${host.trim()}`;
84
+ }
85
+
70
86
  function routerAPI() {
71
87
  return {
72
88
  router: {
@@ -74,7 +90,14 @@ function routerAPI() {
74
90
  widget.emit(RouterEvents.REDIRECT, { url, ...data });
75
91
  },
76
92
  link(widget, routeName, data = {}) {
77
- return widget.$dependencies.link(routeName, data);
93
+ const origin = getOrigin(widget);
94
+ const path = widget.$dependencies.link(routeName, data);
95
+
96
+ if (origin && path === '/') {
97
+ return origin;
98
+ }
99
+
100
+ return `${origin}${path}`;
78
101
  },
79
102
  getCurrentRoute(widget) {
80
103
  return widget.$in.router.route;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merkur/plugin-router",
3
- "version": "0.36.0",
3
+ "version": "0.36.5",
4
4
  "description": "Merkur router plugin.",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -68,5 +68,5 @@
68
68
  "dependencies": {
69
69
  "universal-router": "^9.1.0"
70
70
  },
71
- "gitHead": "2471f91d8249ae75e49b2a0da8d0deb93062f014"
71
+ "gitHead": "89939c5215ebe0cb4403b488ebb0400611aba9e3"
72
72
  }