Answer the question
In order to leave comments, you need to log in
How to dynamically load a page through react router?
There are files: index.jsx, alias.jsx
From Router I try to load the Alias component (alias.jsx), but it gives an error
index.jsx
.....
const Alias2 = React.lazy(() => import('./Alias'));
export default function(props) {
return (
<Router>
<TestLinks />
<Switch>
<Route path="/about">
<Aboute/>
</Route>
<Route exact path="/podkatalog/:alias.php" component={Alias} />
</Switch>
</Router>
);
}
function Alias(props){
return (
<div>
<Suspense fallback={<div>Загрузка...</div>}>
<Alias2 />
</Suspense>
</div>
)
}
...
module:{
rules:[
{
test: /\.js|jsx$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: [
[ '@babel/preset-env',
], [
'@babel/preset-react'
]
],
plugins: [
"@babel/plugin-syntax-dynamic-import"
]
}
}
},
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question