Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

redirect() is not correct working with base path #589

Closed
NikolayMakhonin opened this issue Mar 2, 2019 · 1 comment · Fixed by #591
Closed

redirect() is not correct working with base path #589

NikolayMakhonin opened this issue Mar 2, 2019 · 1 comment · Fixed by #591

Comments

@NikolayMakhonin
Copy link

NikolayMakhonin commented Mar 2, 2019

I can reproduce this bug in Opera 58, Chrome 33, Chrome 74 Dev. And only if I go the link from address bar. Click by link is worked correctly.

I set base path as /sapper/page - site worked correctly.
Then added this code to the routes/index.html

export default {
    preload() {
        return this.redirect(302, 'login')
    }
}

Actual redirect behavior:
http://localhost:3000/sapper/page ==> http://localhost:3000/sapper/login
but I expected this:
http://localhost:3000/sapper/page ==> http://localhost:3000/sapper/page/login


I can fix this bug if I change follow line in the file __sapper__/server.js:

if (redirect) {
    console.log(req.baseUrl);
    // const location = url.resolve(req.baseUrl || '/', redirect.location); // Original
    const location = url.resolve((req.baseUrl || '') + '/', redirect.location); // Changed
    res.statusCode = redirect.statusCode;
    res.setHeader('Location', location);
    res.end();
    return;
}
thgh added a commit to thgh/sapper that referenced this issue Mar 2, 2019
thgh added a commit to thgh/sapper that referenced this issue Mar 2, 2019
thgh added a commit to thgh/sapper that referenced this issue Mar 3, 2019
@arxpoetica
Copy link
Member

#593 also seems to be related, if not indirectly

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants