Closed findborg closed 7 years ago
Handling links is relatively easy. In history.js, you can change the third line to be:
const history = createHistory({ basename: '/50' });
And all your links will work without having to change them.
Unfortunately, the bundle.js reference is /bundle.js, so if bundle.js is not in the root, the whole site will be broken. You could change line 8 of index.html to be:
<script src='/50/bundle.js'></script>
While that works, I don't think changing two things is great. One thought I had would be to use an environment variable that defaulted to empty. This way, when you run npm start
or npm run build
you could change the expected base path to whatever you want by running BASE_PATH=/50 npm start
Another issue I noticed while messing with this is that the element doesn't show the URL to which it will go. So when you hover over the actual link, you see the existing link with a hash after it. I can replace the href attribute with the 'to' property, but that doesn't take basepath into account.
Since I don't really use different base paths, let me know how you would like it to work and we can figure something out.
I saw that link hover problem as well. many others will or would complain about access-ability with that. As far as the route is concerned, I like the BASE_PATH idea...
I tested the createHistory code and it works. However, now home does not load with the build.js.(only when clicked does it load). But, it does automatically home when in dev server mode.
I checked for errors, what I am seeing is that even after running yarn build it is injecting the link for the livereload script. Maybe you will see the same thing?? Everything works fine in Start mode... Maybe I am doing something wrong. Of course, I am trying to build and test in the same directory. (for me it is easier to keep organized) that is prob the problem.
What exactly is your workflow? I think I've got something working that I'll push as soon as I can, but I want to make sure I get what you're trying to do.
Well I am using wamp as my server as you know I am on a Windows machine. I have my main site files working there in local host so when 5try something new or test something I just drop it into a new folder ex 50 or testa and go about my testing. So I was working with vue.js and actually had to solve some of the same routing issues with that as well. I like to keep an index file in the root of the file so I can build and see if what I am trying to make or play with is working. But, if I build something I like. I want to be able to just drop it anywhere and it will still work.
So do you build the app by running npm run build
and then copy the contents of the build directory into your 50 or testa directory? If so, the commit I just pushed should help you. I added an APP_BASE_PATH (I was worried BASE_PATH would conflict with some other package) environment variable that will modify everything that needs to be modified. I tested that it works using npm start
and I did a simple test using a python web server to emulate what I think your workflow is.
Let me know how this works for ya!
I'll give it a go and let you know
Since I haven't heard back, I'm going to close this. Feel free to reopen or create a new issue if the solution doesn't work for you.
Sorry, I have been sidetracked. Where do I set the APP_BASE_PATH?
Also, I see that you have the link hover working. Nice
I found it, and it is working. Niiice I am still getting this error in the console http://localhost:35729/livereload.js?snipver=1 net::ERR_CONNECTION_REFUSED (anonymous) @ bundle.js:2764
Also, note the deep linking is not working. If I try to go to localhost/50/about/bob directly, I get a 404. But, if I go to lh/50/ it does load and the links work as long as I stay on session. Do I still need to edit the router page? I give that a go and see what happens
I wanted to ask before I go changing anything around, Is there a way to make the base route just drop and go? For example, my test folder for this is 50 but when I click a link it goes to localhost/about... not localhost/50/about... I know how to add the 50 folder to the route. But, like I said, I was wondering if there was a way to just make it work no matter where it is placed in a folder system?