Issue 1:
trailing slash in link for legit page works for client side navigation but leads to not found bundle and 404 on hard refresh (ssr)

Bug report

Describe the bug

let me know if title needs further clarification.

all relevant issues has been closed with reasoning that its been fixed in 6-canary (I believe it is not) or by improved serve (which is true only in perhaps production static export).

I'm rewriting my existing blog to next.js and i previously used trailing slashes. Latest serve can help with it once i build my next.js powered blog. But in order to fix dev env i need either to get rid of trailing slashes and utilize 301 Moved Permanently in prod; or live with broken trailing slash support in dev.

To Reproduce

Here is minimal reproducible case (link to repro repo is below snippet):

// pages/index.js
import Link from "next/link";

export default () => (
<Link href="/about/">
<a>About</a>
</Link>
);

// pages/index.js
export default () => "about";

Minimal reproducible repo https://github.com/iamstarkov/next.js-trailing-slash-bug-demo

clone repo git clone https://github.com/iamstarkov/next.js-trailing-slash-bug-demo

change directory cd next.js-trailing-slash-bug-demo

install deps yarn

run dev: yarn dev

open http://localhost:3000/

open devtools' network tab

observe http://localhost:3000/_next/static/development/pages/about.js being 200ed

observe http://localhost:3000/_next/on-demand-entries-ping?page=/about/ being 200ed

observe http://localhost:3000/about/ being 404ed

observe persistent attempts to resolve http://localhost:3000/about/

observe in the terminal Client pings, but there's no entry for page: /about/

refresh the page

observe 404 page.

remove trailing slash in the url or click http://localhost:3000/about

observe page being 200ed

to ensure error persistence repeat steps 5-15 once.

Expected behavior

/about/ shouldnt be resolved as 404 not found

/about/ should be resolved as 200 ok

Server should not print Client pings, but there's no entry for page: /about/

both /about and /about/ should work the same way

Screenshots

N/A

System information

OS: macOS High Sierra 10.13.6 (17G65)

Browser (should not matter, but can repro'ed in chrome 69.0.3497.100 and safari Version 12.0 (13606.2.11) (was the same for safari 11)

Version of Next.js: 7.0.0 (could repro on 5.x and 6.x)

Additional context

Add any other context about the problem here.

If you change this code in https://github.com/zeit/next.js/blob/459c1c13d054b37442126889077b7056269eeb35/server/on-demand-entry-handler.js#L242-L249

or node_modules/next/dist/server/on-demand-entry-handler.js locally

const { query } = parse(req.url, true)
const page = normalizePage(query.page)
+ console.log('query.page', query.page);
+ console.log('page', page);
+ console.log('Object.keys(entries)', Object.keys(entries));
const entryInfo = entries[page]

// If there's no entry.
// Then it seems like an weird issue.
if (!entryInfo) {
const message = `Client pings, but there's no entry for page: ${page}`

and restart next dev and open http://localhost:3000/ and click about link then:

for /about

query.page /about
page /about
Object.keys(entries) [ '/', '/about' ]

for /about/:

query.page /about/
page /about/
Object.keys(entries) [ '/', '/about' ]
Client pings, but there's no entry for page: /about/

I think the problem (at least part of it) is in inability of onDemandEntryHandler's middleware to find page in entries if page has trailing slash.

I hope my 2 hours of investigation and preparation can help with fixing this issue.

Issue 2:
Hi,

Would be nice to be able to modify the webpack configuration using the interface that webpack-chain provides.

My proposal is to do something like poi does, as is described in poi>docs>webpack. Doing it that way the user have the choice of using webpack-chain or mutate the configuration object directly (which is not the safest way).

@sergiodxa, @liweinan0423, @emattias What do you think about it? Should I submit a PR?

I have searched the issues of this repository and believe that this is not a duplicate.