検索条件
	タグで絞り込み
		Node.js(1)
		Node.js::npm(1)
		ソフトウェア(1)
		ソフトウェア::Git(1)
		ライブラリ(1)
		ライブラリ::React(1)
		言語(1)
		言語::TypeScript(1)
	
	
	全3件
	(1/1ページ)
	
	
SSHが使えない悲劇に出会った時に。CentOS 7.7で確認。
パスワードは平文保存されるっぽいので、そこら辺は注意が必要。
git config --global credential.helper cachegit config --global credential.helper 'cache --timeout=31536000'react-routerでRouteを切る実装例
| Env | Ver | 
|---|---|
| React | 17.0.1 | 
| react-router-dom | 5.2.0 | 
| TypeScript | 4.1.3 | 
index.tsximport React from 'react';
import ReactDOM from 'react-dom';
import './index.scss';
import { BrowserRouter } from 'react-router-dom';
import { RootRoute } from './routes/RootRoute';
// ドメインルート以外にReactを設置する場合に必要
// e.g. `https://www.example.com/react/` に設置する場合 `/react` を設定
const basename = process.env.REACT_APP_BASE_NAME ?? undefined;
ReactDOM.render(
  <React.StrictMode>
    {/* `useHistory()` 用のDIラッパー */}
    <BrowserRouter basename={basename}>
      {/* ルーティング設定をまとめたコンポーネント */}
      <RootRoute />
    </BrowserRouter>
  </React.StrictMode>,
  document.getElementById('root')
);
AppRoute.tsRouteに対して展開できるように記述しておくexport const AppRoute = {
  // React のルート定義
  root: {
    path: '/',
    key: '/',
    exact: true, // 完全一致
    component: App,
  },
  // 404 定義
  notfound: {
    component: NotFound,
  },
  // `/foo` 以下のルーティング定義
  foo: {
    // `/foo` のルート定義
    root: {
      path: '/foo',
      key: '/foo',
      component: FooRoute,
    },
    // 以下、 `/foo` 配下のページのルーティング定義
    hoge: {
      path: '/foo/hoge',
      key: '/foo/hoge',
      component: HogePage,
    },
    piyo: {
      path: '/foo/piyo',
      key: '/foo/piyo',
      component: PiyoPage,
    },
  },
};
RootRoute.tsxexport const RootRoute = () => {
  return (
  {/* `Route` は `Switch` で囲む */}
  <Switch>
    {/* root */}
    <Route {...AppRoute.root} />
    {/* foo */}
    <Route {...AppRoute.foo.root} />
    {/* bar */}
    <Route {...AppRoute.bar.root} />
    {/* 404 */}
    <Route {...AppRoute.notfound} />
  </Switch>
  );
};
FooRoute.tsx/foo階層配下の管理用export const FooRoute = () => {
  return (
  {/*
    `Context` は `Switch` の外に出す
    `Switch` の中に `Context` を書くと更に `Switch` でネストする必要がある
  */}
  <FooContext.Provider value={FooContextDefault}>
    <Switch>
    {/* eslint-disable-next-line array-callback-return */}
    {Object.entries(AppRoute.foo).map(([idx, route]) => {
      if (idx !== 'root') {
      /* `'root'` 以外の全ノードを展開 */
      return <Route {...route} />;
      }
    })}
    {/* 404 */}
    <Route {...AppRoute.notfound} />
    </Switch>
  </FooContext.Provider>
  );
};
自作npmコマンドを蹴る方法のメモ
| Env | Ver | 
|---|---|
| Node.js | 12.18.3 | 
| npm | 6.14.8 | 
npm initとか適当に"bin": {
  "my-npm-command": "./index.js"
}
#!/usr/bin/env node
console.log('my-npm-command');
npm linkを叩き、my-npm-commandを実行して動いてればOK
npm unlink