Skip to content
Advertisement

Having difficulty adding a second route

So I’m new to VueJs so excuse any mistakes I make here. I have a simple front end application, which is meant to be two pages long. There’s an index route and a game route. The game route takes a path variable name that is meant to be displayed on the screen.

I’ve added the route, imported the components but whenever I try accessing the URL it just displays the index page. Does anyone know what I’m doing wrong? Thanks!

Here is my index.js file

JavaScript

Here is my game.vue file (It’s incomplete, I just want to get it to load first):

JavaScript

Advertisement

Answer

You’re using hash mode by default that allows to access the routes prefixed by # sign :

JavaScript

if you want to access it like localhost:8080/game/bob you should add history mode to the router definition:

JavaScript
Advertisement