Commit graph

17 commits

Author SHA1 Message Date
Miroslav Petrov
47d2dfdb54
Update examples/active-class-name (#62506)
### Description
The current implementation of the activeClassName example doesn't
support the `UrlObject` type for the "href" Link prop.
For example
```
<ActiveLink
  activeClassName="active"
  className="nav-link"
  href={{
    pathname: "/[slug]",
    query: {
      slug: "dynamic-route",
    },
  }}
>
  Dynamic Route
</ActiveLink>
```
won't work.

### Suggestion
We can use the `resolveHref` function to handle all cases.

Co-authored-by: Sam Ko <sam@vercel.com>
2024-02-26 16:40:16 +00:00
Steven
4466ba436b
chore(examples): use default prettier for examples/templates (#60530)
## Description
This PR ensures that the default prettier config is used for examples
and templates.

This config is compatible with `prettier@3` as well (upgrading prettier
is bigger change that can be a future PR).

## Changes
- Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will
be needed upgrading to prettier@3)
- Added `examples/.prettierrc.json` with default config (this will
change every example)
- Added `packages/create-next-app/templates/.prettierrc.json` with
default config (this will change every template)

## Related

- Fixes #54402
- Closes #54409
2024-01-11 16:01:44 -07:00
xixinRunBoy
058f6f1cb0
active-class-name example style js has not taken effect (#56136)
example/active-class-name: the Nav.tsx's style has not taken effect
change <style jsx> to <style jsx global>

Co-authored-by: chenxixin <chenxixin>
2023-10-26 20:19:14 -05:00
Josh Slate
b2df2cff26
chore(examples): Update active-class-name example (#43581)
I updated the `active-class-name` example to stop using the legacy behavior.

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm build && pnpm lint`
- [x] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-12-01 12:21:57 +00:00
Tim Neutkens
ab42da0626
Run next/link codemod for Next.js 13 on examples (#41913) 2022-10-30 21:00:45 +01:00
Max Proske
3a22c4c554
Convert active-class-name example to TypeScript (#37676)
The Contributing guidelines say TypeScript should be leveraged for new examples, so I thought I'd convert this example over. 

I also:
- Upgraded all dependencies
- Replaced the `prop-types` package with TypeScript types

## Documentation / Examples

- [X] Make sure the linting passes by running `pnpm lint`
- [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-14 08:49:09 +00:00
xhoantran
a38e144099
Update examples/active-class-name (#34205)
## Description

According to `Next.js` useRouter documentation:

- `asPath`: The path (including the query) shown in the browser without the configured basePath or locale.
- `pathname`: Current route. That is the path of the page in /pages, the configured basePath or locale is not included.

`asPath` should not be used as the props of components. There are many cases that `asPath` not working as expected. For example:

- `asPath` is different on server-side and client-side.
- `asPath` can contains `id` and `query`.

## Suggestion

- Warning the use of `asPath` can lead to the conflict of client and server-side.
- Update `useRouter` document.

## Bug

- [x] Related issues linked using `fixes #number`

Fixes: https://github.com/vercel/next.js/issues/34144
Fixes: https://github.com/vercel/next.js/issues/34016
Fixes: https://github.com/vercel/next.js/issues/34197
2022-02-11 00:51:56 +00:00
Aubrey
7d8e0c512f
updated active-class-name example to also demo a [slug] path (#15924)
updated example for [active-class-name](f00ad581a1/examples/active-class-name) to also support a `[slug].js` page that matches on `as` instead of `href` (as `href` would be `/[slug]`)

> This does not demo `[..slug].js` as this requires possible custom code for determining the slug path part for the active classname. i.e. page tree active nodes. A possible other example or another PR on this example.

Has possible information for:
 * https://github.com/vercel/next.js/issues/7410
2020-08-06 01:26:48 +00:00
Henrik Wenz
b280c82a5e
[Examples] Fix active-class-name (#12931) 2020-05-15 12:44:46 -04:00
Joe Haddad
18a9c7e371
Improve linting rules to catch more errors (#9374)
* Update `packages/`

* Update examples

* Update tests

* Update bench

* Update top level files

* Fix build

* trigger
2019-11-10 19:24:53 -08:00
Martin Grubinger
81066a396c Fix example active-class-anme: Add support for children of ActiveLink without a className. (#9271)
* Fix example active-class-anme: Add support for children of ActiveLink without a className.

* Update examples/active-class-name/components/ActiveLink.js

Co-Authored-By: Luis Alvarez D. <luis@zeit.co>
2019-10-31 14:05:12 -05:00
Henrik Wenz
ce25f747e7 Refactor active-class-name example (#8558)
- use router hook instead of hoc
- simplify ActiveLink component
- add prop-types
- add function names
- use fragments instead of divs
2019-08-29 12:22:42 -04:00
Tim Neutkens
9c4eefcdbf
Add prettier for examples directory (#5909)
* Add prettier for examples directory

* Fix files

* Fix linting

* Add prettier script in case it has to be ran again
2018-12-17 17:34:32 +01:00
Brent Clark
24d862cd6b Remove console.log derp (#3810)
* fix copy pasta issue

* remove console.log derp

* resolve merge conflicts
2018-02-15 11:02:33 +01:00
Brent Clark
a8d07af355 use null instead of empty string for coerced className (#3771) 2018-02-12 10:10:01 +01:00
Tim Neutkens
c8059b9f12 Make sure linting passes 2017-10-31 08:58:00 +01:00
Remy Sharp
4c18678d54 Create example of activeClassLink using withRouter (#3188) 2017-10-30 15:24:31 +01:00