8.43.0 • Published 26 days ago

@takeshape/routing v8.43.0

Weekly downloads
389
License
MIT
Repository
-
Last release
26 days ago

@takeshape/routing

@takeshape/routing is a module designed to be used on the frontend of a site generated with TakeShape. It is library agnostic so it can be used with React, Vue, etc.

Installation

npm install --save @takeshape/routing

Routing

The route function is used to generate links on the client side. It allows you to create links to your static site with content fetched from the TakeShape GraphQL API. It's especially useful when building out dynamic search or taxonomy pages.

route is a curried function which consumes the following params

  • config - Object - The tsg.yml config object use yaml-loader to import it
  • routeName - String - The name of the desired route
  • content - Object - An object containing the properties referenced in the route string

tsg.yml

templatePath: src/templates
staticPath: static
buildPath: build

routes:
  post:
    path: /blog/:title/
    template: pages/posts/individual.html

search-result-link.jsx

import {route as createRoute} from '@takeshape/routing';
import config from '../tsg.yml';

const route = createRoute(config);

export default function SearchResultLink({content}) {
  return <a href={route(content._contentTypeName, content)}>{content.title}</a>;
}

where the content prop would be:

{
  "_contentTypeName": "post",
  "title": "How TakeShape Routing Works"
}

Rendered HTML:

<a href="/blog/how-@takeshape/routing-works">How TakeShape Routing Works</a>

Image URLs

getImageUrl converts asset paths into URLs suitable for use in an <img> tag.

import {getImageUrl} from '@takeshape/routing';

<img src={getImageUrl('/my/image/path')}/>

<img src={getImageUrl('/my/image/path', {w: 300, h: 250})}/> // image resized to 300x250

TakeShape uses Imgix as its image CDN. Imgix provides rich suite of image manipulation capatbilities that are accessible using the second argument of getImageUrl. See their docs for all the possibilites!

Asset URLs

Not all assets in TakeShape are images and sometimes you just want a simple download link. Use getAssetUrl in this case.

import {getAssetUrl} from '@takeshape/routing';

<a href={getAssetUrl('/my/asset/path')} download>
  Download Me
</a>;
8.30.0

2 months ago

8.11.0

3 months ago

8.15.1

2 months ago

8.38.0

1 month ago

8.15.0

2 months ago

8.38.1

1 month ago

8.38.2

1 month ago

8.15.2

2 months ago

8.6.0

3 months ago

8.26.0

2 months ago

8.15.4

2 months ago

8.31.0

2 months ago

8.12.0

2 months ago

8.35.1

1 month ago

8.12.1

2 months ago

8.35.2

1 month ago

8.16.0

2 months ago

8.7.0

3 months ago

8.23.0

2 months ago

8.23.2

2 months ago

8.27.0

2 months ago

8.27.1

2 months ago

8.39.2

1 month ago

8.39.3

1 month ago

8.42.3

27 days ago

8.42.1

27 days ago

8.32.0

1 month ago

8.13.0

2 months ago

8.36.1

1 month ago

8.36.2

1 month ago

8.17.1

2 months ago

8.8.1

3 months ago

8.8.3

3 months ago

8.8.2

3 months ago

8.20.0

2 months ago

8.20.1

2 months ago

8.20.2

2 months ago

8.24.0

2 months ago

8.28.0

2 months ago

8.43.0

26 days ago

8.10.0

3 months ago

8.33.0

1 month ago

8.10.1

3 months ago

8.37.0

1 month ago

8.21.1

2 months ago

8.25.0

2 months ago

8.4.0

3 months ago

8.1.0

3 months ago

8.3.0

3 months ago

7.239.0

3 months ago

8.0.1

3 months ago

8.2.0

3 months ago

7.236.0

3 months ago

7.238.1

3 months ago

7.238.0

3 months ago

7.234.0

3 months ago

7.237.0

3 months ago

7.235.0

3 months ago

7.222.1

3 months ago

7.222.0

3 months ago

7.217.0

3 months ago

7.219.0

3 months ago

7.230.1

3 months ago

7.230.0

3 months ago

7.225.0

3 months ago

7.225.1

3 months ago

7.223.0

3 months ago

7.216.1

3 months ago

7.233.0

3 months ago

7.231.1

3 months ago

7.228.0

3 months ago

7.224.1

3 months ago

7.222.3

3 months ago

7.215.1

4 months ago

7.214.2

4 months ago

7.214.0

4 months ago

7.214.1

4 months ago

7.213.2

4 months ago

7.213.1

4 months ago

7.212.0

4 months ago

7.211.1

4 months ago

7.213.0

4 months ago

7.211.0

4 months ago

7.210.0

4 months ago

7.209.0

4 months ago

7.209.2

4 months ago

7.208.1

4 months ago

7.208.0

4 months ago

7.207.1

4 months ago

7.205.0

4 months ago

7.204.0

4 months ago

7.203.1

4 months ago

7.202.0

4 months ago

7.199.0

4 months ago

7.198.1

4 months ago

7.198.0

4 months ago

7.197.0

4 months ago

7.195.2

4 months ago

7.194.2

4 months ago

7.195.0

4 months ago

7.194.0

4 months ago

7.134.4

6 months ago

7.90.0

7 months ago

7.38.2

9 months ago

7.14.0

11 months ago

7.8.1

11 months ago

7.3.0

11 months ago

6.8.0

1 year ago

5.54.0

1 year ago

5.54.1

1 year ago

5.28.0

1 year ago

5.25.0

1 year ago

5.9.1

1 year ago

5.9.0

1 year ago

5.7.4

2 years ago

5.7.1

2 years ago

5.2.0

2 years ago

5.0.8

2 years ago

5.0.7

2 years ago