Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48bd132
commit 0e9f5bf
Showing
16 changed files
with
3,197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": ["react", "env"], | ||
"plugins": [ | ||
"add-module-exports" | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
src/React.Sample.Router.CoreMvc/Content/components/expose-components.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require('expose-loader?React!react'); | ||
require('expose-loader?ReactDOM!react-dom'); | ||
require('expose-loader?ReactDOMServer!react-dom/server'); | ||
|
||
require('expose-loader?RootComponent!./home.jsx'); |
78 changes: 78 additions & 0 deletions
78
src/React.Sample.Router.CoreMvc/Content/components/home.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Component } from 'react'; | ||
import { | ||
Link, | ||
BrowserRouter, | ||
Route, | ||
Switch, | ||
StaticRouter, | ||
Redirect | ||
} from 'react-router-dom'; | ||
|
||
class Navbar extends Component { | ||
render() { | ||
return ( | ||
<ul> | ||
<li> | ||
<Link to="/">Home</Link> | ||
</li> | ||
<li> | ||
<Link to="/about">About</Link> | ||
</li> | ||
<li> | ||
<Link to="/contact">Contact</Link> | ||
</li> | ||
</ul> | ||
); | ||
} | ||
} | ||
|
||
class HomePage extends Component { | ||
render() { | ||
return <h1>Home</h1>; | ||
} | ||
} | ||
|
||
class AboutPage extends Component { | ||
render() { | ||
return <h1>About</h1>; | ||
} | ||
} | ||
|
||
class ContactPage extends Component { | ||
render() { | ||
return <h1>Contact</h1>; | ||
} | ||
} | ||
|
||
export default class HomeComponent extends Component { | ||
render() { | ||
const app = ( | ||
<div> | ||
<Navbar /> | ||
<Switch> | ||
<Route exact path="/" render={() => <Redirect to="/home" />} /> | ||
<Route path="/home" component={HomePage} /> | ||
<Route path="/about" component={AboutPage} /> | ||
<Route path="/contact" component={ContactPage} /> | ||
<Route | ||
path="*" | ||
component={({ staticContext }) => { | ||
if (staticContext) staticContext.status = 404; | ||
|
||
return <h1>Not Found :(</h1>; | ||
}} | ||
/> | ||
</Switch> | ||
</div> | ||
); | ||
|
||
if (typeof window === 'undefined') { | ||
return ( | ||
<StaticRouter context={this.props.context} location={this.props.path}> | ||
{app} | ||
</StaticRouter> | ||
); | ||
} | ||
return <BrowserRouter>{app}</BrowserRouter>; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/React.Sample.Router.CoreMvc/Controllers/HomeController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace React.Sample.Router.CoreMvc.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
|
||
namespace React.Sample.Router.CoreMvc | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
BuildWebHost(args).Run(); | ||
} | ||
|
||
public static IWebHost BuildWebHost(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>() | ||
.Build(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/React.Sample.Router.CoreMvc/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:9456/", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"React.Sample.Router.CoreMvc": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "http://localhost:9457/" | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/React.Sample.Router.CoreMvc/React.Sample.Router.CoreMvc.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Folder Include="wwwroot\" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\React.AspNet.Middleware\React.AspNet.Middleware.csproj" /> | ||
<ProjectReference Include="..\React.AspNet\React.AspNet.csproj" /> | ||
<ProjectReference Include="..\React.Core\React.Core.csproj" /> | ||
<ProjectReference Include="..\React.Router\React.Router.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using JavaScriptEngineSwitcher.Core; | ||
using JavaScriptEngineSwitcher.Msie; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using React.AspNet; | ||
|
||
namespace React.Sample.Router.CoreMvc | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public IServiceProvider ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddMvc(); | ||
services.AddReact(); | ||
|
||
// Build the intermediate service provider then return it | ||
return services.BuildServiceProvider(); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseStaticFiles(); | ||
|
||
// Initialise ReactJS.NET. Must be before static files. | ||
app.UseReact(config => | ||
{ | ||
config | ||
.SetReuseJavaScriptEngines(true) | ||
.SetLoadBabel(false) | ||
.SetLoadReact(false) | ||
.AddScriptWithoutTransform("~/components-bundle.generated.js"); | ||
JsEngineSwitcher.Instance.EngineFactories.Add(new MsieJsEngineFactory()); | ||
JsEngineSwitcher.Instance.DefaultEngineName = MsieJsEngine.EngineName; | ||
}); | ||
|
||
app.UseMvc(routes => | ||
{ | ||
routes.MapRoute("default", "{path?}", new { controller = "Home", action = "Index" }); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@using React.AspNet | ||
@using React.Router | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>React Router Sample</title> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
@Html.ReactRouterWithContext("RootComponent", new { }) | ||
<script src="/components-bundle.generated.js"></script> | ||
@Html.ReactInitJavaScript() | ||
</body> | ||
</html> |
10 changes: 10 additions & 0 deletions
10
src/React.Sample.Router.CoreMvc/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"IncludeScopes": false, | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"Logging": { | ||
"IncludeScopes": false, | ||
"Debug": { | ||
"LogLevel": { | ||
"Default": "Warning" | ||
} | ||
}, | ||
"Console": { | ||
"LogLevel": { | ||
"Default": "Warning" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "React.Sample.Router.CoreMvc", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "webpack" | ||
}, | ||
"dependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-loader": "^7.1.2", | ||
"babel-plugin-add-module-exports": "^0.2.1", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-react": "^6.24.1", | ||
"expose-loader": "^0.7.3", | ||
"react": "^16.1.1", | ||
"react-dom": "^16.1.1", | ||
"react-router-dom": "^4.2.2", | ||
"webpack": "^3.8.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
entry: './Content/components/expose-components.js', | ||
output: { | ||
filename: './wwwroot/components-bundle.generated.js' | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jsx?$/, | ||
exclude: /node_modules/, | ||
loader: 'babel-loader' | ||
} | ||
] | ||
} | ||
}; |
Oops, something went wrong.