Error occurs when attempting to access second level route in Vue directly

I am currently utilizing vue-router within my vue application. The application consists of the following routes:

const routes = [
    {name: "home", path: "/", component: Home},
    {name: "user", path: "/user", component: User},
    {name: "edit-user", path: "/user/edit", component: EditUser}
];

const router = new VueRouter({
    routes: routes,
    mode: 'history'
});

When accessed using router-link, both routes work flawlessly as shown below.

<router-link to="/user">Go to user</router-link>
<router-link to="/user/edit">Edit user</router-link>

However, if I try to access the routes directly by refreshing the page, the "/user" route works perfectly fine. On the other hand, the "/user/edit" route displays a black page with a console error message stating the following: (no additional error information provided).

Uncaught SyntaxError: Unexpected token <

I am in need of assistance to resolve this issue. Any help would be greatly appreciated.

Answer №2

The reason behind the problem was quite small. In the main HTML page, the js file was linked in this way:

<script type="text/javascript" src="js/app.js"></script>

To resolve the issue, I simply changed the src value from "js/app.js" to "/js/app.js" like this:

<script type="text/javascript" src="/js/app.js"></script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The reason for my inability to include a fresh method in String.prototype using typescript

I attempted to extend the String.prototype with a new method, but I encountered an issue. interface String { newMethod(): void } String.prototype.newMethod = function() {} Although there were no errors in the typescriptlang.org playground, I received ...

Error: Improper hook call detected with no hooks being used (material-ui v5)

I've created the following basic application: import Grid from '@material-ui/core/Grid'; function App() { return ( <div className="App"> <Grid container spacing={2}> <Grid item xs={8}> ...

Setting the property of an object member using an array member within a JavaScript singleton

My JavaScript code includes a "singleton" class like this: ExpressionValidator = { // A map of function names to the enumerated values that can be passed to it. functionParamValues: { "Func1": ["value1", "value2", "value3"], "F ...

What is the method for obtaining the values from these newly generated text fields?

Every time I click on the "ADD TEXTBOX" button, a new HTML textbox is dynamically created using jQuery's append method. However, I am struggling to figure out how to retrieve and store the values of these textboxes in PHP. $(w).append('<div&g ...

Is it advisable to prevent Set and Map from having unspecified generics in TypeScript?

Upon reviewing some old code that I wrote, I realized that I had neglected to specify a generic type for a Set. The type was set as Set<unknown>. Strangely, despite this, I found that I could still utilize all the methods of the Set without encounter ...

Establishing updated file path for resources in JavaScript based on environment

I'm currently facing an issue with my external Javascript file that uses the getScript() function to execute another JS file. Both files are located on static.mydomain.com, as I am trying to set up a Content Delivery Network (CDN) for the first time. ...

Combining the power of ExpressJS with a dynamic blend of ejs and React for an

My current setup involves a NodeJS application with an Express backend and EJS for the frontend. The code snippet below shows an example route: router.get("/:name&:term", function(req, res) { Course.find({ courseName: req.params.name, courseTerm: req.p ...

Is there any issue that you can spot with this js / jQuery code?

Presented below is a script that prompts the user to confirm clicking a button based on a system setting. The system setting is saved in a hidden field established from the code-behind. Markup: <asp:HiddenField ID="hfConfirmOnApproval" runat="server" ...

ng-click="showInventory()" onClick="currentTemplate='/inventory.html'" Not

I'm facing an issue with my menu list. When I apply the ng-repeat directive, it seems to not work properly. However, when I remove the ng-repeat, everything functions as expected. <div class="reports_header_tabs_holder"> <span ng-repea ...

analyzing properties through unit testing

Currently in the process of writing unit tests for computed properties. I have a file called fileOne.ts : export const fileOne = () => { const fx1 = computed ( () => { ... } ); const fx2 = computed ( () => { ... } ); const fx3 = comp ...

What is the best way to validate a particular class in javascript?

Need help checking if a specific id has a particular class. Unsure of the process? Here's the code snippet where the attempt at checking the id for a specific class is visible within the homeTransition function. function homeTransition() { ...

The main content will be displayed on the sub-routes of the child

I'm feeling uncertain about the routes for children. For example, I have an 'About' route with 'me' as a sub-route: { path: '/about', name: 'About', component: About, children: [ { ...

Creating a module within a component in angular - step by step guide

I am interested in dynamically creating a component inside another component. This will allow me to pass my dynamic HTML template directly to the decorator like this: //code /** * @param template is the HTML template * @param container is @ViewChild(& ...

retrieve Excel document via POST request

I have a scenario where my API endpoint accepts JSON input and returns an Excel file directly instead of providing a link to download the file. How can I use JQuery AJAX to download this file? Here is the backend code snippet: public function postExcel() ...

When starting a new project with Angular 7, the option to set up routing is automatically included without asking for confirmation

After switching from Angular 6 to version 7, I encountered an issue while creating a new project in CLI using ng new [app-name]. It simply starts without giving me the option to include routing or styling in my project. Just a heads up, I am currently run ...

Guide to displaying a particular item in Vue 3

Currently, I am embarking on a project that requires the functionality to print a specific element of my webpage. After some research, I came across a mixin/plugin known as VueHtmlToPaper which seems to be the perfect solution for what I need. However, I a ...

Transferring information to a server with node.js

I have implemented AJAX to send data to the server. The code snippet I am using is: function post(url) { return new Promise(function(resolve, reject) { var req = new XMLHttpRequest(); req.open('POST', url); req.onload = function() ...

Reduce the page zoom to 75% without changing the page layout

I am looking to implement a forced zoom out feature on a webpage, reducing the overall size to 75%. Unfortunately, I am unable to disclose the specific code as it belongs to the company I work for. Despite researching various methods online, including solu ...

Mobile devices do not trigger the initialization of jQuery animation

I've been working on adjusting the opacity of a class using the jQuery hover function, without utilizing the <script> tag. <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"> </script> Below is the code I ...

Using Vuejs and Chartjs to transform a doughnut chart into a gauge through rotation

New to vue.js and seeking advice. I am using Chartjs and trying to rotate my pie chart to look like a gauge. Unsure about the JavaScript implementation, no errors in console. Any guidance would be appreciated. Not sure if "options" are placed correctly c ...