@shuvi/platform-web 1.0.44 → 1.0.45

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.
@@ -10,6 +10,7 @@ export interface CreateAppServer {
10
10
  (options: {
11
11
  req: ShuviRequest;
12
12
  ssr: boolean;
13
+ basename: string;
13
14
  }): InternalApplication;
14
15
  }
15
16
  export interface CreateAppClient {
@@ -23,13 +23,13 @@ export const createApp = ({ routes, appData, appComponent }) => {
23
23
  if (app) {
24
24
  return app;
25
25
  }
26
- const { appState, ssr } = appData;
26
+ const { appState, ssr, basename } = appData;
27
27
  let history;
28
28
  if (historyMode === 'hash') {
29
- history = createHashHistory();
29
+ history = createHashHistory({ basename });
30
30
  }
31
31
  else {
32
- history = createBrowserHistory();
32
+ history = createBrowserHistory({ basename });
33
33
  }
34
34
  const router = createRouter({
35
35
  history,
@@ -17,10 +17,11 @@ import logger from '@shuvi/utils/logger';
17
17
  import { serializeServerError } from '../helper/serializeServerError';
18
18
  const { SHUVI_SERVER_RUN_LOADERS } = SERVER_CREATE_APP.events;
19
19
  export const createApp = options => {
20
- const { req, ssr } = options;
20
+ const { req, ssr, basename } = options;
21
21
  const history = createMemoryHistory({
22
22
  initialEntries: [(req && req.url) || '/'],
23
- initialIndex: 0
23
+ initialIndex: 0,
24
+ basename
24
25
  });
25
26
  const router = createRouter({
26
27
  history,
@@ -42,7 +42,7 @@ export class ReactServerView {
42
42
  : router.resolve(location, pathname).href, status);
43
43
  }
44
44
  // handle router internal redirect
45
- return redirect(pathname);
45
+ return redirect(router.resolve(router.current).href);
46
46
  }
47
47
  const loadableModules = [];
48
48
  let htmlContent = undefined;
@@ -20,6 +20,7 @@ function renderToHTML({ req, serverPluginContext }) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
21
  let result;
22
22
  const renderer = new renderer_1.Renderer({ serverPluginContext });
23
+ const { config: { ssr }, appConfig: { router: { basename } } } = serverPluginContext;
23
24
  const { serverCreateAppTrace } = req._traces;
24
25
  const { application } = resources_1.default.server;
25
26
  const app = serverCreateAppTrace
@@ -28,7 +29,8 @@ function renderToHTML({ req, serverPluginContext }) {
28
29
  })
29
30
  .traceFn(() => application.createApp({
30
31
  req,
31
- ssr: serverPluginContext.config.ssr
32
+ ssr,
33
+ basename
32
34
  }));
33
35
  try {
34
36
  yield serverCreateAppTrace
@@ -39,7 +41,7 @@ function renderToHTML({ req, serverPluginContext }) {
39
41
  result = yield renderer.renderView({
40
42
  req,
41
43
  app: app.getPublicAPI(),
42
- ssr: serverPluginContext.config.ssr
44
+ ssr
43
45
  });
44
46
  }
45
47
  finally {
@@ -5,9 +5,11 @@ const base_1 = require("./base");
5
5
  class SpaRenderer extends base_1.BaseRenderer {
6
6
  renderDocument({ req, app }) {
7
7
  const assets = this._getMainAssetTags(req);
8
+ const { router: { basename } } = this._serverPluginContext.appConfig;
8
9
  const appData = {
9
10
  ssr: false,
10
- pageData: {}
11
+ pageData: {},
12
+ basename
11
13
  };
12
14
  const document = {
13
15
  htmlAttrs: {},
@@ -40,7 +40,7 @@ class SsrRenderer extends base_1.BaseRenderer {
40
40
  Object.assign(acc, data);
41
41
  return acc;
42
42
  }, {});
43
- const appData = Object.assign(Object.assign({}, result.appData), { ssr: true, appState: store.getState(), pageData });
43
+ const appData = Object.assign(Object.assign({}, result.appData), { ssr: true, appState: store.getState(), pageData, basename: router.basename });
44
44
  appData.runtimeConfig = (0, shuvi_singleton_runtimeConfig_1.getPublicRuntimeConfig)() || {};
45
45
  const document = {
46
46
  htmlAttrs: Object.assign({}, result.htmlAttrs),
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const router_1 = require("@shuvi/router");
16
+ const utils_1 = require("@shuvi/router/lib/utils");
16
17
  const resources_1 = __importDefault(require("@shuvi/service/lib/resources"));
17
18
  const module_replace_plugin_1 = __importDefault(require("@shuvi/toolpack/lib/webpack/plugins/module-replace-plugin"));
18
19
  function acceptsHtml(header, { htmlAcceptHeaders = ['text/html', '*/*'] } = {}) {
@@ -85,7 +86,8 @@ class OnDemandRouteManager {
85
86
  }
86
87
  ensureRoutes(pathname) {
87
88
  return __awaiter(this, void 0, void 0, function* () {
88
- const matchedRoutes = (0, router_1.matchRoutes)(resources_1.default.server.pageRoutes, pathname) || [];
89
+ const { router: { basename } } = this._serverPluginContext.appConfig;
90
+ const matchedRoutes = (0, router_1.matchRoutes)(resources_1.default.server.pageRoutes, pathname, (0, utils_1.normalizeBase)(basename)) || [];
89
91
  const modulesToActivate = matchedRoutes
90
92
  .map(({ route: { __componentRawRequest__ } }) => __componentRawRequest__)
91
93
  .filter(Boolean);
@@ -6,6 +6,9 @@ import { IServerModule } from './shuvi-runtime-server';
6
6
  import { addRoutes, addMiddlewareRoutes, addApiRoutes } from './features/filesystem-routes/hooks';
7
7
  export {};
8
8
  declare module '@shuvi/service/lib/resources' {
9
+ interface IGetRoutes {
10
+ (routes: IPageRouteRecord[]): IPageRouteRecord[];
11
+ }
9
12
  interface IResources {
10
13
  server: {
11
14
  server: IServerModule;
@@ -16,6 +19,7 @@ declare module '@shuvi/service/lib/resources' {
16
19
  createApp: CreateAppServer;
17
20
  };
18
21
  view: IViewServer;
22
+ getRoutes: IGetRoutes;
19
23
  };
20
24
  documentPath: string;
21
25
  clientManifest: IManifest;
@@ -10,6 +10,7 @@ export interface CreateAppServer {
10
10
  (options: {
11
11
  req: ShuviRequest;
12
12
  ssr: boolean;
13
+ basename: string;
13
14
  }): InternalApplication;
14
15
  }
15
16
  export interface CreateAppClient {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/platform-web",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -72,15 +72,15 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@next/react-refresh-utils": "12.1.6",
75
- "@shuvi/error-overlay": "1.0.44",
76
- "@shuvi/hook": "1.0.44",
77
- "@shuvi/platform-shared": "1.0.44",
78
- "@shuvi/router": "1.0.44",
79
- "@shuvi/router-react": "1.0.44",
80
- "@shuvi/runtime": "1.0.44",
81
- "@shuvi/shared": "1.0.44",
82
- "@shuvi/toolpack": "1.0.44",
83
- "@shuvi/utils": "1.0.44",
75
+ "@shuvi/error-overlay": "1.0.45",
76
+ "@shuvi/hook": "1.0.45",
77
+ "@shuvi/platform-shared": "1.0.45",
78
+ "@shuvi/router": "1.0.45",
79
+ "@shuvi/router-react": "1.0.45",
80
+ "@shuvi/runtime": "1.0.45",
81
+ "@shuvi/shared": "1.0.45",
82
+ "@shuvi/toolpack": "1.0.45",
83
+ "@shuvi/utils": "1.0.45",
84
84
  "content-type": "1.0.4",
85
85
  "core-js": "3.6.5",
86
86
  "doura": "0.0.13",
@@ -98,7 +98,7 @@
98
98
  "whatwg-fetch": "3.0.0"
99
99
  },
100
100
  "peerDependencies": {
101
- "@shuvi/service": "1.0.44"
101
+ "@shuvi/service": "1.0.45"
102
102
  },
103
103
  "devDependencies": {
104
104
  "@shuvi/service": "workspace:*",