Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router.push Does not know about and Nullifies route prefix/ basename #4118

Closed
rayhooker opened this issue Apr 6, 2018 · 3 comments
Closed

Comments

@rayhooker
Copy link

rayhooker commented Apr 6, 2018

The application has a route prefix and is homed at /src. I have the appropriate assetprefix and node handlers to cause next to properly recognize the prefix and properly render the page. Every thing seems to work (see below).

var prefix = '/src'
const router = express.Router();
const server = express()
const router = express.Router();
server.use(body.json())
        server.use((req, res, next) => {
        console.log("Use body.json",req.url)
        req.db = db
        next()
})
server.use(`${prefix}`,router)
router.get('*', (req, res) => {
        return handle(req, res)
});
server.listen(PORT)

The main issue is when I use router.push to update the parameters so that a back re-renders the page. I am using shallow true:

var newroute = Router.pathname+"?"+filterstring;
Router.push(newroute, newroute, { shallow: true }) 

So starting with:

http://localhost:3000/src/index

I push the parameter year but I get:

http://localhost:3000/index?year=2016

instead of

http://localhost:3000/src/index?year=2016

If I add the route prefix to the router push it does work but at first the next router gives a 404 and sends it to the server to render. Need for the router not to nullify the basename/ prefix of /src. How can I do that or is this a bug? Otherwise a back gives errors because the application is not homed at the server root but has a prefix.

@timneutkens
Copy link
Member

Can you please provide a repository to reproduce, it's hard to determine if this is even an issue/bug since you didn't follow the issue template 🙏

@rayhooker
Copy link
Author

Here is the repository:
https://github.com/rayhooker/demoReportSelectorServer

Basically if you bring up the app by:
node index.js
navigate to:
http://localhost:3000/src/

Then click on one the selector button to change the view state such as "Districts". It should at the latest options including the defaults such as:

http://localhost:3000/src?
viewSelect=districts&year=2017&type=Both&level=All&district=All&lang=english

Instead it does not realize that there is a base route of /src, so the new url becomes:
http://localhost:3000/?
viewSelect=districts&year=2017&type=Both&level=All&district=All&lang=english

In this case the applicable line that pushes the state is line 111 of the component "schoolsView.js". Is there not some way to say "the base route is not '/' but '/src/'"?

Ray

@timneutkens
Copy link
Member

Tracking this here: #4998

@lock lock bot locked as resolved and limited conversation to collaborators Mar 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants