当我刷新页面时,单击链接后响应获取请求URL更改
当我尝试重定向到我的任务详细信息页面并想刷新它时,我在index.html中发现了一个错误404文件,因为我的样式表路径和scripts.js路径从localhost:8080/styles.css更改为localhost:8080/tasks/style.css,我不知道为什么会发生这种情况 我的html代码:当我刷新页面时,单击链接后响应获取请求URL更改,url,get,request,reactjs,react-router,Url,Get,Request,Reactjs,React Router,当我尝试重定向到我的任务详细信息页面并想刷新它时,我在index.html中发现了一个错误404文件,因为我的样式表路径和scripts.js路径从localhost:8080/styles.css更改为localhost:8080/tasks/style.css,我不知道为什么会发生这种情况 我的html代码: <!doctype html> <html class="no-js" lang=""> <head> <meta charset="ut
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='http://fonts.googleapis.com/cssfamily=Open+Sans:400,300,600' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- build:css css/application.css -->
<link rel="stylesheet" href="styles.css">//BREAKS HERE
<!-- endbuild -->
</head>
<body>
<main class="site-content" id="main">
<p>Main content</p>
</main>
<!-- build:js js/application.js -->
<script src="scripts.js"></script>//AND BREAKS HERE
<!-- endbuild -->
</body>
您需要在标记的src中正确设置路径
<!-- build:css css/application.css -->
<link rel="stylesheet" href="/styles.css">//BREAKS HERE
<!-- endbuild -->
<!-- build:js js/application.js -->
<script src="/scripts.js"></script>//AND BREAKS HERE
<!-- endbuild -->
//在这里休息
//在这里休息
请注意“/”。它告诉浏览器从域名的根目录查看。如果你不说了。。。它将其附加到url的当前路径。在这种情况下,应用程序组件没有路径,任务路由的路径不应以/开头。看看这是否有效:
<Route path="/" handler={App}>
<DefaultRoute handler={Login} />
<Route name="login" path="login" handler={Login} />
<Route name="dashboard" path="dashboard" handler={Dashboard} />
<Route name="tasks" path="tasks/:id" handler={Task} />
</Route>
我尝试了一下,得到了以下结果:警告:失败的propType:不应该有“路径”道具警告。js:48警告:不应该有“路径”道具不变量。js:42未捕获错误:不变量冲突:您不能有多个名为“登录”的路由(@cwbutler answer解决了我的问题)啊,我的问题<代码>应该可以工作,因为我必须使用DefaultRoute和使用相同处理程序的Route,就像这样。
<!-- build:css css/application.css -->
<link rel="stylesheet" href="/styles.css">//BREAKS HERE
<!-- endbuild -->
<!-- build:js js/application.js -->
<script src="/scripts.js"></script>//AND BREAKS HERE
<!-- endbuild -->
<Route path="/" handler={App}>
<DefaultRoute handler={Login} />
<Route name="login" path="login" handler={Login} />
<Route name="dashboard" path="dashboard" handler={Dashboard} />
<Route name="tasks" path="tasks/:id" handler={Task} />
</Route>