小编mda*_*shs的帖子

React Router v4 Redirect无法正常工作

检查完这样的条件后,我有一条路线重定向

<Route exact path="/" render={()=>(
Store.isFirstTime ? <Redirect to="intro" /> : <Home state={Store}/>)}/>
Run Code Online (Sandbox Code Playgroud)

当条件为真但未安装组件时,URL会更改.组件代码的其余部分如下所示.

render() {
    return (
      <div>
        ...
        <Route exact path="/" render={()=>(
          Store.isFirstTime ? <Redirect to="intro" /> : <Home state={Store} />         
        )} />
        <Route path="/intro" render={()=>(<IntroWizard state={Store.userInfo}/>)} />
        <Route path="/home" render={()=>(<Home state={Store}/>)} />
        <Route render={()=>(<h1>404 Not Found</h1>)} />
        <Footer />
      </div>
    );
  }
Run Code Online (Sandbox Code Playgroud)

My App Component包含在BrowserRouter中,就像thi一样

ReactDOM.render(<BrowserRouter>
    <App/>
</BrowserRouter>,
  document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud)

当我直接在浏览器中点击url时,就像'localhost:3000/intro'组件成功安装,但是当它通过重定向时,它不会显示组件.我如何解决它?

编辑

所以缺少一个细节,我尝试创建另一个项目来重现问题.我的应用程序组件是来自mobx-react的观察者,它的导出方式如下所示

let App = observer(class App { ... })
export default App
Run Code Online (Sandbox Code Playgroud)

我用一个示例代码创建了这个repo来重现你可以使用它的问题 https://github.com/mdanishs/mobxtest/

因此,当组件被包装到mobx-react观察器中时,重定向不起作用,否则它工作正常

javascript reactjs react-router react-router-v4

25
推荐指数
4
解决办法
3万
查看次数

Android - 显示电话簿联系人并选择一个

我想通过点击按钮显示电话簿中的联系人列表,然后从中选择一个联系人然后检索其联系号码?我不想制作我的自定义列表,有没有办法使用内置功能的机器人?

android android-emulator android-intent android-layout

12
推荐指数
2
解决办法
2万
查看次数

如何让eslint解析jsconfig中映射的路径

在我的 nextjs 项目中,我已经映射了路径jsconfig.json以进行简单的绝对导入

{
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "@/*": ["./*"]
    },
    "target": "es6",
    "module": "commonjs",
    "experimentalDecorators": true
  }
}
Run Code Online (Sandbox Code Playgroud)

我的导入路径如下所示 import { VIEW } from '@/src/shared/constants';

我的eslintrc.js设置指定为

module.exports = {
    ... ,
    settings: {
        "import/resolver": {
          alias: {
            extensions: [".js"],
            map: ["@", "."]
          }
        }
      }
}
Run Code Online (Sandbox Code Playgroud)

我仍然收到错误消息,说无法解析“@/what/ever/my/path/is”

如何让eslint实现jsconfig路径

javascript eslint webpack babeljs

9
推荐指数
1
解决办法
2168
查看次数

如何告诉Visual Studio代码相对路径

我正在使用create-react-app工具创建一个react-app,因此它使用webpack进行模块捆绑.具有以下目录结构

-my-app
--node_modules
--src
---components
----somecomponent
-----SomeComponent.jsx
----someothercomponent
-----SomeOtherComponent.jsx
----main.js
----public
Run Code Online (Sandbox Code Playgroud)

为了避免很多../../(相对路径的点点斜线),我NODE_PATH=./src在package.json中设置了如下所示

"scripts": {
    "start": "NODE_PATH=./src react-scripts start",
    "build": "NODE_PATH=./src react-scripts build",
}
Run Code Online (Sandbox Code Playgroud)

所以我现在可以像这样导入我的模块

import SomeComponent from "/components/somecomponent/SomeComponent"
Run Code Online (Sandbox Code Playgroud)

因此,即使更改目录结构也不会经常破坏我的代码.但是有了这个,我的VSCode不会识别路径,因此不会显示智能感知,我该如何解决?

visual-studio-code vscode-settings

8
推荐指数
1
解决办法
4611
查看次数

根据内容调整Unity 4.6 UI Text的高度

我是团结最新UI的新手.我对UI Text Element的了解是,我们可以在水平边界中包装文本,但如果它到达下一行,则它会溢出或截断.如果它适合高度,字体大小会减小.我想要的是根据文本区域包含的内容调整文本区域的高度,而不影响文本区域内的字体大小.

我将有许多文本元素作为父级面板的子级,面板本身将是可滚动容器的子级.所以我必须计算所有孩子的身高来调整父面板的高度.

我该如何实现?

c# text unity-game-engine

7
推荐指数
1
解决办法
1万
查看次数

Angular 2 - AppModule声明的意外模块

我是角度新手并尝试在具有以下目录结构的Angular2应用程序中分离我的模块.

我在AppModule中声明了我的模块和其他组件,但是我在浏览器控制台中遇到错误 Unexpected HomeModule declared by AppModule

app
--authentication
---- htmls, ts, css
--home
----dashboard
--------html, ts, css
----representativs
--------html, ts, css
----home-routing.module.ts
----home.module.ts
--app.routing.ts
--app.module.ts
Run Code Online (Sandbox Code Playgroud)

app.module.ts

import { routing } from "./app.routing"
import { AppComponent } from './app.component';
import { HomeModule } from "./home/home.module";

@NgModule({
  imports: [BrowserModule, routing, HttpModule, ReactiveFormsModule],
  declarations: [ AppComponent, HomeModule],
  bootstrap: [AppComponent],
  providers: [UserAuthenticationService]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)

home.module.ts

import { NgModule } from '@angular/core';
import { DashboardComponent } from './dashboard/dashboard.component';
import { …
Run Code Online (Sandbox Code Playgroud)

routing ng-modules angular

7
推荐指数
1
解决办法
1万
查看次数

SQL - 缺少右括号

我试图在Oracle 11g中执行此脚本并收到以下错误,我不知道我在哪里错过了paranthesis或错误是什么,请帮助我弄明白这一点.

脚本:

CREATE TABLE User_Role ( 
  user_role_id INT  NOT NULL  , 
  Users_user_id INT  FOREIGN KEY REFERENCES Users(user_id), 
  User_Types_user_type VARCHAR(20) FOREIGN KEY REFERENCES User_Types(user_type),  
  PRIMARY KEY(user_role_id) 
)
Run Code Online (Sandbox Code Playgroud)

错误:

ORA-00907:遗失右侧的父母

sql oracle oracle10g oracle11g

4
推荐指数
1
解决办法
3万
查看次数

android中的XML SAXParserException

使用以下 I 代码,我试图获取 xml 中的节点列表,但应用程序崩溃并引发 saxparser 异常。

这是我尝试使用的 xml

<?xml version="1.0"?><Root><ResponseCode>1</ResponseCode><ResponseMessage>Reported Successfully</ResponseMessage><ResultSet><Post><id>1</id><title>Garbage Problem near my home</title><comment>We the citizens have been facing the problems of garbage since 2004 , kindly fix it , authorities are concerned</comment><imagepath></imagepath><cordx>24.818688</cordx><cordy>67.029686</cordy><tag>Garbage</tag><userid>1</userid><departmentid>1</departmentid><response></response><createdOn>2013-03-23 14:44:43</createdOn><status>2</status></Post></ResultSet></Root>
Run Code Online (Sandbox Code Playgroud)

这是我试图用来从 xml 中获取的代码

InputSource is = new InputSource();
is.setCharacterStream(new StringReader(result));
XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
String code = xPath.evaluate("/Root/ResponseCode/text()", is);
if(code.compareTo("1")==0){
    Log.d("Responce Code", code);
    NodeList nodeList = (NodeList) xPath.evaluate("//Post", is,XPathConstants.NODESET);
for(int i=0; i<nodeList.getLength(); i++){
    Node n=nodeList.item(i);
    Element element = (Element) n; …
Run Code Online (Sandbox Code Playgroud)

xml xpath android xml-parsing android-xml

2
推荐指数
1
解决办法
1206
查看次数

如何避免级联ngOnInit?

我有两个与父子关系相关的组件。父组件的 ngOnInit 方法检查用户是否登录,如果未登录,则导航到登录页面。

class ParentComponent implements OnInit{
    ngOnInit(){
        if(!authService.loggedIn){ 
           //navigate to login screen code
           return;
        }
    }
}

class ChildComponent implements OnInit{
    ngOnInit(){
        /** POINT TO BE NOTED **/
        // this function is also called even if ngOnInit 
        // of parent navigates to different component and returns.
        // do some stuff with userService.token
        // but because token isn't available the calls fail
    }
}
Run Code Online (Sandbox Code Playgroud)

如果父组件想要导航到其他组件,如何阻止此级联 OnInit 调用?

angular2-template angular2-routing ngoninit angular

1
推荐指数
1
解决办法
345
查看次数