fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

Escaped params #146

Closed trotzig closed 6 years ago

trotzig commented 6 years ago

When urls are constructed in the Link component, all params are URI encoded so that they won't break routing. When params are read however, they are never decoded. This leads to an inconsistent behavior between the server and the client when params are passed down the page component as query. On the server, they come down untouched (encoded). On the client, they are not encoded.

Consider this link:

  <Link route="foo" params={{ b: 'f/g' }}><a>Foo</a></Link>

and this page component

  FooPage.getInitialProps = async ({ query }) => {
    console.log(query.b);
  }

On the server, this page would log "f%2Fg" when navigated to. On the client it would log "f/g".

By decoding params before they are injected into the query params, we get the same behavior on the client and the server. We also make the behavior consistent with how regular query params work.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.03%) to 96.137% when pulling 7f23584d7056a795b7bc25e6061ee993a4f51581 on trotzig:escaped-params into 4630d1961dbf65772fc957bb36a38cbfcb072318 on fridays:master.

trotzig commented 6 years ago

Ping @fridays, not sure if you watch new PRs coming in.

fridays commented 6 years ago

Thank you, great catch!