@umijs/renderer-react 4.0.4 → 4.0.7

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/dist/browser.js CHANGED
@@ -84,25 +84,31 @@ export function renderClient(opts) {
84
84
  const manifest = window.__umi_manifest__;
85
85
  if (manifest) {
86
86
  const routeIdReplaced = id.replace(/[\/\-]/g, '_');
87
- const preloadId = 'preload-' + routeIdReplaced;
87
+ const preloadId = `preload-${routeIdReplaced}.js`;
88
88
  if (!document.getElementById(preloadId)) {
89
- const key = Object.keys(manifest).find((k) => k.startsWith(routeIdReplaced + '.'));
90
- if (!key)
91
- return;
92
- let file = manifest[key];
93
- const link = document.createElement('link');
94
- link.id = preloadId;
95
- link.rel = 'preload';
96
- link.as = 'script';
97
- // publicPath already in the manifest,
98
- // but if runtimePublicPath is true, we need to replace it
99
- if (opts.runtimePublicPath) {
100
- file = file.replace(new RegExp(`^${opts.publicPath}`),
101
- // @ts-ignore
102
- window.publicPath);
103
- }
104
- link.href = file;
105
- document.head.appendChild(link);
89
+ const keys = Object.keys(manifest).filter((k) => k.startsWith(routeIdReplaced + '.'));
90
+ keys.forEach((key) => {
91
+ if (!/\.(js|css)$/.test(key)) {
92
+ throw Error(`preload not support ${key} file`);
93
+ }
94
+ let file = manifest[key];
95
+ const link = document.createElement('link');
96
+ link.rel = 'preload';
97
+ link.as = 'style';
98
+ if (key.endsWith('.js')) {
99
+ link.as = 'script';
100
+ link.id = preloadId;
101
+ }
102
+ // publicPath already in the manifest,
103
+ // but if runtimePublicPath is true, we need to replace it
104
+ if (opts.runtimePublicPath) {
105
+ file = file.replace(new RegExp(`^${opts.publicPath}`),
106
+ // @ts-ignore
107
+ window.publicPath);
108
+ }
109
+ link.href = file;
110
+ document.head.appendChild(link);
111
+ });
106
112
  }
107
113
  }
108
114
  // server loader
package/dist/routes.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // @ts-ignore
2
2
  import React from 'react';
3
- import { Navigate } from 'react-router-dom';
3
+ import { generatePath, Navigate, useParams } from 'react-router-dom';
4
4
  import { RouteContext } from './routeContext';
5
5
  export function createClientRoutes(opts) {
6
6
  const { routesById, parentId, routeComponents } = opts;
@@ -27,11 +27,19 @@ export function createClientRoutes(opts) {
27
27
  return route;
28
28
  });
29
29
  }
30
+ function NavigateWithParams(props) {
31
+ const params = useParams();
32
+ const propsWithParams = {
33
+ ...params,
34
+ to: generatePath(props.to, params),
35
+ };
36
+ return React.createElement(Navigate, { ...propsWithParams });
37
+ }
30
38
  function createClientRoute(opts) {
31
39
  const { route } = opts;
32
40
  const { redirect, ...props } = route;
33
41
  return {
34
- element: redirect ? (React.createElement(Navigate, { to: redirect })) : (React.createElement(RouteContext.Provider, { value: {
42
+ element: redirect ? (React.createElement(NavigateWithParams, { to: redirect })) : (React.createElement(RouteContext.Provider, { value: {
35
43
  route: opts.route,
36
44
  } },
37
45
  React.createElement(RemoteComponent, { loader: opts.routeComponent, loadingComponent: opts.loadingComponent || DefaultLoading }))),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/renderer-react",
3
- "version": "4.0.4",
3
+ "version": "4.0.7",
4
4
  "description": "@umijs/renderer-react",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/renderer-react#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",