index.cshtml в React SPA приложении. как?
От: VladCore  
Дата: 25.03.19 13:54
Оценка:
Как подсунуть razor-page вместо public/index.html в ASP.NET MVC with React?

Вот цитата из react на похожую тему:

## Injecting Data from the Server into the Page

Similarly to the previous section, you can leave some placeholders in the HTML that inject global variables, for example:

```js
<!doctype html>
<html lang="en">
<head>
<script>
window.SERVER_DATA = __SERVER_DATA__;
</script>
```

Then, on the server, you can replace `__SERVER_DATA__` with a JSON of real data right before sending the response. The client code can then read `window.SERVER_DATA` to use it. **Make sure to [sanitize the JSON before sending it to the client](https://medium.com/node-security/the-most-common-xss-vulnerability-in-react-js-applications-2bdffbcc1fa0) as it makes your app vulnerable to XSS attacks.**


Вопрос. Как?

По идее должно быть так:
app.UseSpa(spa =>
{
    spa.Options.SourcePath = "ClientApp";
    // Так увы нельзя :)
    spa.Options.DefaultPage = "/index.cshtml"

    if (env.IsDevelopment())
    {
        spa.UseReactDevelopmentServer(npmScript: "start");
    }
});


Но увы и ах.
Даже Гугл увы не знает что такое ISpaBuilder DefaultPage. Его мегамозг предлагает поискать "ispa builder default page"

P.S. Кстати сама цитата не откуда нибудь взята, а она добавляется в каждый проект из шаблона и в Visual Studio и в Rider
Отредактировано 25.03.2019 13:58 VladCore . Предыдущая версия . Еще …
Отредактировано 25.03.2019 13:54 VladCore . Предыдущая версия .
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.