|
| 1 | +--- |
| 2 | +id: aspnet5 |
| 3 | +layout: docs |
| 4 | +title: Getting Started on ASP.NET 5 |
| 5 | +--- |
| 6 | + |
| 7 | +Getting started with ReactJS.NET on ASP.NET 5 and MVC 6 requires a few more steps compared to previous versions of ASP.NET and MVC. A more fully featured tutorial will be released once the stable release of ASP.NET 5 is out. |
| 8 | + |
| 9 | +Note that ASP.NET 5 is still in beta, and so there may still be some sharp edges. ReactJS.NET requires at least Visual Studio 2015 CTP6 and ASP.NET 5 Beta 3. Additionally, ReactJS.NET does not support the Core CLR at this point in time, so you will need to ensure your project is not referencing it. Remove the `"aspnetcore50": { }` line from your `project.json` file. |
| 10 | + |
| 11 | +Once this has been removed, install the `React.AspNet` package through NuGet. After the package is installed, ReactJS.NET needs to be initialised in your `Startup.cs` file (unfortunately this can not be done automatically like in previous versions of ASP.NET with WebActivator). At the top of the file, add: |
| 12 | +``` |
| 13 | +using React.AspNet; |
| 14 | +``` |
| 15 | + |
| 16 | +Directly above: |
| 17 | + |
| 18 | +```csharp |
| 19 | +// Add MVC services to the services container. |
| 20 | +services.AddMvc(); |
| 21 | +``` |
| 22 | + |
| 23 | +Add: |
| 24 | + |
| 25 | +```csharp |
| 26 | +services.AddReact(); |
| 27 | +``` |
| 28 | + |
| 29 | + |
| 30 | +Directly above: |
| 31 | + |
| 32 | +```csharp |
| 33 | +// Add static files to the request pipeline. |
| 34 | +app.UseStaticFiles(); |
| 35 | +``` |
| 36 | + |
| 37 | +Add: |
| 38 | + |
| 39 | +```csharp |
| 40 | +app.UseRequestServices(); |
| 41 | +app.UseReact(config => |
| 42 | +{ |
| 43 | + // ES6 features are enabled by default. Uncomment the below line to disable them. |
| 44 | + // See http://reactjs.net/guides/es6.html for more information. |
| 45 | + //config.SetUseHarmony(false); |
| 46 | + // Uncomment the below line if you are using Flow |
| 47 | + // See http://reactjs.net/guides/flow.html for more information. |
| 48 | + //config.SetStripTypes(true); |
| 49 | + // If you want to use server-side rendering of React components, |
| 50 | + // add all the necessary JavaScript files here. This includes |
| 51 | + // your components as well as all of their dependencies. |
| 52 | + // See http://reactjs.net/ for more information. Example: |
| 53 | + //config |
| 54 | + // .AddScript("~/Scripts/First.jsx") |
| 55 | + // .AddScript("~/Scripts/Second.jsx"); |
| 56 | +}); |
| 57 | +``` |
| 58 | + |
| 59 | +Finally, add this to `Views/_GlobalImport.cshtml` (or create it if it doesn't exist): |
| 60 | + |
| 61 | +```csharp |
| 62 | +@using React.AspNet |
| 63 | +``` |
| 64 | + |
| 65 | +Once ReactJS.NET has been configured, you will be able to use [on-the-fly JSX to JavaScript compilation](http://reactjs.net/getting-started/usage.html) and [server-side rendering](http://reactjs.net/guides/server-side-rendering.html). |
0 commit comments