Within the Star Wars universe, capital ships typically engage each other at what I consider to be unnecessarily close range reminiscent of the broadside battles of 18th century warships. In the 18th century, such range was necessary due to a lack of accuracy.
Yes, Star Wars has more to do with 19th century naval combat than 21st century. The reasons are: regenerative shielding, slow "lasers", and awful targeting computers.
NOTE: For this answer I am only using on-screen canon. No EU, novels, Clone Wars, etc... it's hard enough to make sense of Star Wars without all that extra and often conflicting information.
In reality we have astonishingly accurate smart weapons. A Tomahawk missile can hit a 1 meter target from 500 miles away. The Advanced Gun System can fire an unguided shell 100km with accuracy within 50 meters.
The Star Wars universe, despite having mastered human level droid intelligence, consistently lacks reliable targeting computers. Star Wars accuracy is closer to early WWII technology.
In the opening of A New Hope we see an Imperial Star Destroyer having a hard time hitting the unmaneuvering Tantive IV. The guns on the Falcon are computer augmented but still manually aimed and have a hard time hitting TIE fighters. At the Battle of Yavin the computer can't hit a 2 meter exhaust port. We see anti-starfighter guns on the Death Star blazing away but rarely a hit. Darth Vader gets a lock on Luke and begins firing yet still misses.
In Empire Strikes Back, three Star Destroyers and four TIE fighters at point blank range only manage to knock out the Millennium Falcon's rear shields. In Return Of The Jedi, dozens of TIE Fighters swarm past the Falcon yet she and the severely outnumbered Rebel starfighters survive the battle.
For whatever reason, targeting computers in Star Wars are terrible.
To add to the problem, Star Wars weapons are incredibly slow.
Despite calling them "lasers", the weapons in Star Wars are fairly slow moving masses of probably some sort of plasma. We can see them whipping by, so they're slower than a bullet. Even missiles are demonstrated to be only barely faster than a Jedi Starfighter in RotS.
Their "lasers" are "dumb" weapons, they have no internal targeting. They can't correct their course if the target changes course. While there's no wind or bullet drop to worry about, this still means that the longer the range the more time the target has to dodge. High rates of fire (Star Wars capital ships fire much faster than capital ships in reality) and short ranges would compensate for this.
Even with bad accuracy, in reality it's still beneficial for a warship to fire at its maximum effective range if nothing else than to try and outrange the enemy. It would also give them room to maneuver, stay in formation, and escape. In WWI, where warships would hit with as low or lower than 1% of their shells, they still fought at range.
But they relied on armor to protect themselves. Armor which could not be repaired in battle. And armor was not perfect, any hit would do some damage, even near misses would cause splinter and structural damage. And much of the ship was outside the armored citadel or exposed on the deck.
Now add shields into the mix. Some starfighters and most larger ships have shields which must be taken down before hits begin to do damage. Most are capable of recharging their shields. In order to be effective, it's not enough to hit your enemy, you have to hit them faster than they can recharge their shields. Combined with inaccuracy, this means attacking at close range.
Star Wars capital ships are a lot like pre-dreadnought battleships. Despite having a few very big, long range guns, they preferred to fight at close range because their accuracy was terrible. They would be covered in lighter intermediate, secondary, and tertiary guns designed to fight at close range where they could reliably hit and smother the enemy.
We only see two instances of anything like fleet battles in the whole Star Wars canon: the Battle of Endor in RotJ and the Battle of Coruscant in RotS. At Endor the strategy is clear:
Lando Calrissian: Yes, I said closer! Move as close as you can, and engage those Star Destroyers at point blank range!
Admiral Ackbar: At that close range we won't last long against those Star Destroyers!
Lando Calrissian: We'll last longer than we will against that Death Star! And we might just take a few of them with us!
Lando's plan is to brawl with the Star Destroyers so the Death Star can't pick their ships off. It's also clear from Ackbar's comment that range is a deciding factor in survival.
This is also support for the terrible targeting computers. The Death Star's superlaser is so inaccurate it cannot fire into the melee without risking hitting its own ships.
At Coruscant, when we join the battle, Grievous has already achieved his goal of capturing Palpatine. Now he needs to escape. Unfortunately for him it seems he took too long and the initial surprise has worn off. Republic reinforcements have arrived and his fleet is trapped. When we join we're already well into the battle and it is a brawl. There are no longer battle lines, just individual ship actions at very close range. I see three overlapping explanations.
One is that both commanders appear to have lost control of the battle. Through damage, communications jamming, exhaustion, or loss of flagships, nobody is in control of their fleets anymore. We certainly don't see Grievous doing much commanding, he's more concerned about he Jedi and Palpatine. Most sci-fi and fantasy battles have this problem, everyone is running/flying around pel-mel with no lines, formations, or unit cohesion; they're all fighting uncoordinated, individual battles. This is a great way to lose the battle. The out-of-universe explanation is the filmmakers have no idea what a real battle looks like and/or think smashing two armies or two fleets together looks cool.
Another is the Republic have deliberately engaged at point blank range in order to trap the Separatist fleet. We don't know the range and effectiveness of interdiction technology at this point in the war. The Republic must prevent the Separatists from escaping with Palpatine, up to and including physically blocking their exit paths.
Finally, the Republic commander may have decided this is too good an opportunity to pass up. They've got the Separatist fleet pinned deep inside Republic territory. Republic reinforcements are pouring in. Crippled Republic ships are close to home and can be repaired, but crippled Separatist ships will be lost. Now is the time to inflict maximum damage, so they close to point blank range and pound away at each other's shields knowing a battle of attrition will benefit the Republic.
In conclusion, Star Wars space battles probably have more in common with 19th century naval tactics than 21st century. Slow projectiles, advantageous defensive technology, and bad targeting computers means Star Wars capital ships must rely more on how much firepower they can throw out per minute at point blank range than on accuracy.
This is in line with British Napoleonic and WWI era tactics. British commanders practiced rapid gun drill to get off their broadsides faster than their enemy and defeat them with "weight of shell". At the Battle of the Nile, Nelson charged and broke the French line, relying on poor accuracy and heavy wooden hulls to protect him. Once there, the British anchored and engaged the French at point blank range firing broadsides from both sides of their ships simultaneously for hours.