You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I was rendering with SSR,Props Introduced to the history. But instead of using the history I passed in, the Router uses \node_modules\react-router-dom\node_modules\history\umd\history.production.min.js the history. occurred document is not defined.
code:
import express from 'express';
import { createMemoryHistory } from 'history';
import React, { Suspense, lazy } from 'react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import * as ReactDOMServer from 'react-dom/server';
const app = express();
const htmlTemplate = function (root) {
return `
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<div id="app">${root}</div>
<script src="index.js"></script>
</body>
</html>
`;
};
const Home = () => <div>Home</div>;
const About = () => <div>About</div>;
const App = (props) => (
<Router history={props.history}>
<Suspense fallback={<div>Loading...</div>}>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</Suspense>
</Router>
);
app.get('/', (req, res) => {
let history = createMemoryHistory({ initialEntries: [req.url] });
console.log('history=', history);
const root = ReactDOMServer.renderToString(<App history={history} />);
res.setHeader('Content-Type', 'text/html');
res.end(htmlTemplate(root));
});
const PORT = 3000;
app.listen(PORT, () => {
console.log('SSR server start at ', PORT);
});
Expected Behavior
In SSR I can use the history I passed in
Actual Behavior
When I was rendering with SSR,Props Introduced to the history. But instead of using the history I passed in, the Router uses \node_modules\react-router-dom\node_modules\history\umd\history.production.min.js the history. occurred document is not defined.
The text was updated successfully, but these errors were encountered:
What version of React Router are you using?
v6 6.3.0
Steps to Reproduce
When I was rendering with SSR,Props Introduced to the history. But instead of using the history I passed in, the Router uses \node_modules\react-router-dom\node_modules\history\umd\history.production.min.js the history. occurred document is not defined.
code:
Expected Behavior
In SSR I can use the history I passed in
Actual Behavior
When I was rendering with SSR,Props Introduced to the history. But instead of using the history I passed in, the Router uses \node_modules\react-router-dom\node_modules\history\umd\history.production.min.js the history. occurred document is not defined.
The text was updated successfully, but these errors were encountered: