@@ -36,7 +36,7 @@ export default function App() {
3636 }}
3737 onError= {(e , history ) => {
3838 if (
39- e . message . startsWith ( ' Cannot find module' ) &&
39+ / not find module/ . test ( e . message ) &&
4040 window .location .pathname !== ' /404'
4141 ) {
4242 history .push (' /404' )
@@ -74,7 +74,50 @@ Then, routed like below automatically
7474
7575<br >
7676
77- ### Recipe of dynamic path
77+ ### Recipe
78+
79+ #### Handling ` not find module ` error
80+
81+ load 404 page keeping URL
82+
83+ ``` js
84+ import React from ' react'
85+ import { BrowserRouter } from ' react-router-dom'
86+ import DynamicRoute from ' react-dynamic-route'
87+
88+ export default function App () {
89+ return (
90+ < BrowserRouter>
91+ < DynamicRoute
92+ page= {path =>
93+ import (' ./pages' + path)
94+ .then (module => module .default )
95+ .catch (e => {
96+ if (/ not find module/ .test (e .message )) {
97+ return import (' ./pages/404' ).then (module => module .default )
98+ }
99+ throw e
100+ })
101+ }
102+ loading= {< div> Loading..< / div> }
103+ props= {{
104+ someProp1,
105+ someProp2, // `someProp1` and `someProp2` are transfered to `module.dedault` above finally
106+ }}
107+ onError= {(e , history ) => {
108+ if (/ Loading chunk \d + failed/ .test (e .message )) {
109+ window .location .reload ()
110+ return
111+ }
112+ throw e
113+ }}
114+ / >
115+ < / BrowserRouter>
116+ )
117+ }
118+ ```
119+
120+ #### dynamic path
78121
79122You can also use dynamic path like below
80123
0 commit comments