score:2

Accepted answer

In order to have a client router that works with both client navigation and direct navigation (like browser bookmark, shared links ans seo) you need to configure a fallback in your server in order to serve index.html (witch will manage client routing)

This becouse brower doesn’t know in which part of your application is routing managed.

If static file are managed by a static server (or if you are behind a reverse proxy) such as nginx you need to use try_files, like that https://stackoverflow.com/a/35039350.

If your static files are managed by your .net application probably you’ll need to configure a default route such as https://stackoverflow.com/a/24564360

During the migration new uri will be resolved as follows:

  1. server side routing
  2. fallback to client side routing

Href inside the application will be resolved as follows:

  1. client side routing
  2. fallback to server side routing.

score:0

You could add each of the .Net routes to your React router config that reloads when landing on each - something like:

<Route path="/my-dot-net-page" component={ReloadComp} />

Where ReloadComp looks something like:

const ReloadComp: React.FC<RouteComponentProps> = props => (window.location.href = props.location.pathname);

This will cause a reload when landing on each of those routes and it should let your .Net webserver handle the route.


Alternatively I think it might be worth holding back on react-router until you move the whole project across to React.

What are you trying to get from it at the moment?

If you are after navigation without full reloads it will not work between the React pages and your .Net pages - a reload will be required.

Once all the views are in React making the change to react-router will be simpler


Related Query

More Query from same tag