@ape-egg/vibe 4.2.1 → 4.3.1

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/spa.js CHANGED
@@ -57,9 +57,13 @@ export const navigate = (path) =>
57
57
  activeRouter ? activeRouter.navigate(path) : location.assign(new URL(path, location.origin));
58
58
 
59
59
  export const setupSpa = ({ routes, onNavigate }) => {
60
- const apply = onNavigate ?? (({ path, route, params, src, name, title }) => {
60
+ const swapTitle = (resolved) => {
61
+ if (resolved?.title) document.title = resolved.title;
62
+ };
63
+ const apply = onNavigate ?? ((resolved) => {
64
+ const { path, route, params, src, name } = resolved;
61
65
  window.$.page = { path, route, params, src, name };
62
- if (title) document.title = title;
66
+ swapTitle(resolved);
63
67
  });
64
68
 
65
69
  const claim = (target) => {
@@ -117,6 +121,7 @@ export const setupSpa = ({ routes, onNavigate }) => {
117
121
 
118
122
  document.addEventListener('click', onClick);
119
123
  addEventListener('popstate', onPopstate);
124
+ if (!onNavigate) swapTitle(resolve(location, routes));
120
125
 
121
126
  const dispose = () => {
122
127
  document.removeEventListener('click', onClick);