Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions website/docs/creating-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down