# svcjs-react

> implementations based svcjs for react

Latest version **0.1.1** (published 2017-01-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install svcjs-react
pnpm add svcjs-react
yarn add svcjs-react
bun add svcjs-react
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-01-22 |
| First published | 2017-01-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Star |
| Maintainers | star3s |

## Links

- npm: https://www.npmjs.com/package/svcjs-react
- Repository: https://github.com/svcjs/react
- Homepage: https://github.com/svcjs/react#readme
- Issues: https://github.com/svcjs/react/issues
- npm.io page: https://npm.io/package/svcjs-react

## Recent versions

- 0.1.1 (latest) — 2017-01-22

## README

# RouteView
a route view component based svcjs for react


# example for RootView
import React from 'react'
import S from 'svcjs';

import RouteView from './RouteView'
import LoadingView from './common/LoadingView'
import LoginView from './common/LoginView'
import MainView from './common/MainView'

class RootView extends RouteView {

	constructor(props) {
		super(props);

		this.subViews = {
			loading: LoadingView,
			login: LoginView,
			main: MainView,
		};

		this.state = {
			name: 'root',
			pathName: '',
			baseUrl: '',
			args: {},
			subPaths: [],
		};
		S.bind('route.paths',[this,'subPaths']);
	}

	render() {
		return this.getSubViews(this.subViews,'single',this.state);
	}
}

export default RootView;


# example for MainView
import React from 'react'
import S from 'svcjs';

import RouteView from '../RouteView'
import AView from '../views/AView'
import BView from '../views/BView'

class MainView extends RouteView {

	constructor(props) {
		super(props);
		this.navs = [
			['a', 'A'],
			['b', 'B'],
		];
		this.subViews = {
			a: AView,
			b: BView,
		};
	}

	render() {

		return (
			<div style={this.getStyle()}>
				<nav>
                    {this.navs.map((data)=> {
                        return (
                            <a onClick={()=> {
                                this.go(data[0]);
                            }} className={(this.getSubName() == data[0] ? 'is-active' : '')}>{data[1]}</a>
                        );
                    })}
				</nav>
				<section>
					{this.getSubViews(this.subViews)}
				</section>
			</div>
		);
	}
}

export default MainView;


# example for location.hash
onhashchange = function (e) {
	S.go(location.hash.substr(1));
};

S.bind('route.paths', (k, paths)=> {
	location.hash = '#' + S.routeUrl;
});


# use route
ReactDOM.render(
	<RootView/>,
	document.getElementById('body')
);
S.go('/loading');
S.go(['main','user?page=2','detail?id=123']);
S.go('../list');
S.go('detail',{id=1,showMore=false});

---
_Source: https://npm.io/package/svcjs-react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
