I wrote a react router code like this and it works
@react.component
let make = () => {
<div>
<Header />
{
switch RescriptReactRouter.useUrl().path {
| list{} => <StockOverview />
| list{"detail"} => <StockDetail />
| _ => <PageNotFound />
}
}
<Footer />
</div>
}
However If I change this code to
@react.component
let make = () => {
<div>
<Header />
{
switch RescriptReactRouter.useUrl().path {
| list{} => <StockOverview />
| list{"detail", symbol} => <StockDetail symbol />
| _ => <PageNotFound />
}
}
<Footer />
</div>
}
Now when I say http://localhost:8001/detail/MSFT
it crashes at runtime with error
[Error] SyntaxError: Unexpected token '<' (anonymous function) (index.js:1)
Here are the details of my webpack configuration of the dev server
devServer: {
historyApiFallback: {
index: './index.js',
disableDotRule: true,
rewrites: [
{
from: /\.(js|css|svg|png|jpg|json|woff|woff2|ttf)$/,
to: function (context) {
return context.parsedUrl.pathname.replace(/^\/.*\//, '/');
},
},
],
},
static: {
directory: outputDir,
},
compress: true,
port: 8001
}
I also tried
devServer: {
historyApiFallback: true,
static: {
directory: outputDir,
},
compress: true,
port: 8001
}
but now it gives error
[Error] Refused to execute http://localhost:8001/detail/index.js as script because "X-Content-Type-Options: nosniff" was given and its Content-Type is not a script MIME type.