-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FallbackToFile options for serving apps with client-side routing. #104
Comments
Pre-requirements: Produce steps: npx create-react-app myapp
cd myapp
npm install -S react-router
npm add react-router-dom@6 history@5
Update import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'
ReactDOM.render(
<Router>
<Routes>
<Route path="*" element={<App />}></Route>
</Routes>
</Router>,
document.getElementById('root')
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
Then build and serve: yarn build
cd build
dotnet-serve
index.html is served when accessing 'http://localhost:54515' but not served when acessing 'http://localhost:54515/anypath' info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:54515/anypath - -
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/1.1 GET http://localhost:54515/anypath - - - 404 - text/html 0.4621ms
index.html will match the browser url path to select component which should rendered. dotnet-serve may serve './index.html' when accessing path '/any'. |
Ok, I see what you are saying now. It sounds like you want all unknown routes to redirect to some default file. This behavior doesn't seem to me to be like a common use case. I don't plan to implement this, but I will leave this request open in case I am missing something. Other users - please upvote if you want support for this feature request. |
it's honestly the only reason I couldn't use it |
this is a very common scenario for SPA apps, including blazor wasm |
I don't develop features myself (project status #43), but if this is something you would like to contribute, feel free to send a pull request. |
I have a react+typescript app use the
React BrowserRouter
.For example, if I used React Router with a route for
/todos
,dotnet-serve
will response a HTTP 404 .This is because when there is a fresh page load for a
/todos
, thedotnet-server
looks for the file build/todos{.html/htm} and does not find it. Thedotnet-server
should to be configured to respond to a request to/todos
by serving index.html.Describe the solution you'd like
Add options to configure
FallbackToFile(...)
endpoints. Such as :dotnet serve --fallback-to-file "index.html"
The text was updated successfully, but these errors were encountered: