Skip to content
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
10 changes: 5 additions & 5 deletions packages/docs/src/pages/qwikcity/routing/default-index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Sometimes the route component gets too complex, and placing the whole implementa
```
- src/
- routes/
- index.tsx # http://server/
- index.tsx # https://example.com/
- some/
- index.tsx # http://server/some
- index.tsx # https://server/some
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed one...

- path/
- index.tsx # http://server/some/path
- _other_component.tsx # this file is ignored and not mapped to any URL.
- index.tsx # https://example.com/some/path
- _other_component.tsx # this file is ignored and not mapped to any URL because of the leading underscore.
```

### `_` prefix

From time to time, there is a need to place files into the `src/routes` folder without them showing up on any route. In such a case use the `_` prefix to let Qwik City knows that the file is private and should not be exposed on any route.
Occasionally, there is a need to place files into the `src/routes` folder without them showing up on any route. In this case, use the `_` prefix to let Qwik City know that the file is private and should not be exposed.
12 changes: 6 additions & 6 deletions packages/docs/src/pages/qwikcity/routing/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ Routing is a way to map public URLs for a site to specific components declared i

## Basic routing

In its simplest form, the URL the user sees `http://server/some/path`, will be mapped to the `some/path` component in the `src/routes` folder.
In the Qwik City router, folders map to paths. For example, if the user sees `https://example.com/some/path`, the component exported at `src/routes/some/path` (either `.mdx` or `.tsx`) will be shown.

```
- src/
- routes/
- some/
- path.tsx # http://server/some/path
- path.tsx # https://example.com/some/path
```

## Implementing a Component

To return HTML for a specific route you will need to implement a component. For `.tsx` file the component must be exported as `default`. (Alternatively, you can use `.mdx` extension discussed [later](/qwikcity/content/mdx).)
To return HTML for a specific route you will need to implement a component. For `.tsx` files the component must be exported as `default`. Alternatively, you can use `.mdx` extension discussed [later](/qwikcity/content/mdx).


```typescript
Expand All @@ -34,11 +34,11 @@ export default component$(() => {

### `_` prefix

From time to time, there is a need to place files into the `src/routes` folder without them showing up on any route. In such a case use the `_` prefix to let Qwik City knows that the file is private and should not be exposed on any route.
Occasionally, there is a need to place files into the `src/routes` folder without them showing up on any route. In this case, use the `_` prefix to let Qwik City know that the file is private and should not be exposed.

## `@qwik-city-plan`

The route information is stored in files. This is great for developer ergonomics but not useful for creating bundles and chunks. In addition, in some environments, such as edge functions, there is no file system that can be accessed. For this reason, it is necessary to serialize the route information into a single file. This is done through the `@qwik-city-plan` import.
Qwik City stores route information in files on disk. This is great for developer ergonomics but not useful for creating bundles and chunks. Additionally, in some environments - such as edge functions - there is no file system that can be accessed. For this reason, it is necessary to serialize the route information into a single file. This is done through the `@qwik-city-plan` import.

```typescript
import cityPlan from '@qwik-city-plan';
Expand All @@ -55,4 +55,4 @@ Qwik City also supports:
- [Nested layouts](/qwikcity/layout/overview)
- [Menus](/qwikcity/content/menu)

These are discussed later.
These are discussed later.
6 changes: 3 additions & 3 deletions packages/docs/src/pages/qwikcity/routing/pathless.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ At times components get so complex that using `index.ts` is not enough, and they
- routes/
- some/
- path/
- _complex-component/ # Notice the `_` prefix
- index.tsx # http://server/some/path (`_complex-component` is not used.)
- _other_component.tsx # this file is ignored and not mapped to any URL.
- _complex-component/ # Notice the underscore prefix
- index.tsx # https://example.com/some/path (the _complex-component folder is ignored)
- _other_component.tsx # this file is ignored and not mapped to any URL because of the leading underscore.
```
45 changes: 45 additions & 0 deletions packages/docs/src/pages/qwikcity/routing/route-parameters.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renaming this file requires a rename in INDEX file as well.

title: Qwik City - Route Parameters
---

# Qwik City - Route Parameters

Route Parameters are parts of the URLs that are extracted into parameters.

Imagine that you have a page with the following URLs where `[skuId]` can be any of the thousands of products that you have in your database. It would be impractical to create a route for each product. Instead, we need to define a Route Parameter (a part of the URL) that will be used to extract the `[skuId]`.

- `https://example.com/sku/[skuId]`
- Will match: `https://example.com/sku/1234`
- Will match: `https://example.com/sku/xyz-567`
- `http://example.com/sku/[skuId]/details`
- Will match: `https://example.com/sku/1234/details`

```
- src/
- routes/
- sku/
- [skuId]/
- index.js # https://example.com/sku/1234
- details.js # https://example.com/sku/1234/details
```


## Retrieving the Route Parameter from the URL

Once we have `[skuId]` in the URL, we need a way to retrieve it. This can be done by using `useLocation()` API.

```typescript
import { useLocation } from '@builder.io/qwik-city';

export default component$(() => {
const location = useLocation();

return (
<Host>
<h1>SKU</h1>
<p>Pathname: {location.pathname}</p>
<p>Sku Id: {location.params.skuId}</p>
</Host>
);
});
```
45 changes: 0 additions & 45 deletions packages/docs/src/pages/qwikcity/routing/slugs.mdx

This file was deleted.