fix(v2): make proper path to pages in TS (#2334)

This commit is contained in:
Alexey Pyltsyn 2020-02-27 04:59:02 +03:00 committed by GitHub
parent 590de95234
commit 68a5cd5df1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 1 deletions

View file

@ -0,0 +1,22 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import Head from '@docusaurus/Head';
export default class Home extends React.Component {
render() {
return (
<div>
<Head>
<title>Hello</title>
</Head>
<div>TypeScript...</div>
</div>
);
}
}

View file

@ -33,6 +33,10 @@ describe('docusaurus-plugin-content-pages', () => {
permalink: '/',
source: path.join('@site', pluginPath, 'index.js'),
},
{
permalink: '/typescript',
source: path.join('@site', pluginPath, 'typescript.tsx'),
},
{
permalink: '/hello/world',
source: path.join('@site', pluginPath, 'hello', 'world.js'),

View file

@ -61,7 +61,7 @@ export function objectWithKeySorted(obj: Object) {
}
const indexRE = /(^|.*\/)index\.(md|js|jsx|ts|tsx)$/i;
const extRE = /\.(md|js)$/;
const extRE = /\.(md|js|tsx)$/;
/**
* Convert filepath to url path.

View file

@ -41,6 +41,12 @@ Once you save the file, the development server will automatically reload the cha
Each page doesn't come with any styling. You will need to import the `Layout` component from `@theme/Layout` and wrap your contents within that component if you want the navbar and/or footer to appear.
:::tip
You can also create a page in TypeScript, in which case the its file name should use the `.tsx` extension, eg. `hello.tsx`.
:::
## Routing
If you are familiar with other static site generators like Jekyll and Next, this routing approach will feel familiar to you. Any JavaScript file you create under `/src/pages/` directory will be automatically converted to a website page, following the `/src/pages/` directory hierarchy. For example: